Skip to content

Handling optional fields with mapOf() #348

Answered by TomWright
ericgoetz asked this question in Q&A
Discussion options

You must be logged in to vote

This feature has been added here: #355.

Docs are available here: https://daseldocs.tomwright.me/functions/ordefault


I'm working on a feature to support this.

Current version looks like this:

$ echo '{
  "-LCr5pXw_fN32IqNDr4E": {
    "bookCategory": "poetry",
    "locale": "en-us",
    "mediaType": "book",
    "publisher": "Pomelo Books",
    "title": "Sound Waves",
    "type": "poetry"
  },
  "-LDDHjkdY0306fZdvhEQ": {
    "ISBN13": "978-1534402966",
    "bookCategory": "fiction",
    "title": "What Can You Do with a Toolbox?",
    "type": "picturebook"
  }
}' | go run cmd/dasel/main.go -r json 'all().mapOf(projectId,key(),title,title,bookCategory,bookCategory,type,type,locale,orDefault(l…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by TomWright
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants