-
Hello, I have input JSON data in this shape:
That I want to be output as CSV approximately like this:
The problem is that many of the fields are optional, which breaks mapOf. Is there a way to give mapOf a default value for missing fields? Here is my query, so far:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
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(locale,string(unknown)))'
{
"bookCategory": "poetry",
"locale": "en-us",
"projectId": "-LCr5pXw_fN32IqNDr4E",
"title": "Sound Waves",
"type": "poetry"
}
{
"bookCategory": "fiction",
"locale": "unknown",
"projectId": "-LDDHjkdY0306fZdvhEQ",
"title": "What Can You Do with a Toolbox?",
"type": "picturebook"
} I'm just thinking about alternatives or how it could be improved. PR is here: #355 |
Beta Was this translation helpful? Give feedback.
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: