Excuse my English, I am not a native speaker
I'm new to this so I don't know much
I am trying to extract some values from a json file with xidel with the following command in windows cmd but it's not working
xidel MyFile.json -e '$json//options/option/*[@option_id="D-ES"]/content_id'
Generally the json file has three options, English, Spanish and Portuguese, I only want all the values related to Spanish
I want to extract the following values
"group_id": "******",
"content_id": "******",
"current_content": "*****",
"option_id": "D-ES",
"subtitle": *****,
"id": "ES",
"desc": "Español",
And put the extracted values as follows
"group_id"-"*****","content_id"-"*****","current_content"-"*****","option_id"-"D-ES"-"subtitle"- *****,"id"- "ES""desc"- "Español",
This is part of my json file
{
"original": {
"id": "ING",
"desc": "Inglés"
},
"dubbed": "true",
"subbed": "false",
"options": {
"option": [
{
"group_id": "922450",
"content_id": "284951",
"current_content": "false",
"option_id": "D-ES",
"audio": "ES",
"subtitle": null,
"option_name": "dubbed",
"id": "ES",
"desc": "Español",
"label_short": "Dob. Español",
"label_large": "Doblada al Español",
"intro_start_time": null,
"intro_finish_time": null,
},
{
"group_id": "275495",
"content_id": "243856",
"current_content": "false",
"option_id": "D-PT",
"audio": "PT",
"subtitle": null,
"option_name": "dubbed",
"id": "PT",
"desc": "Portugués",
"label_short": "Dob. Portugués",
"label_large": "Doblada al Portugués",
"intro_start_time": null,
"intro_finish_time": null,
},
{
"group_id": "248954",
"content_id": "245238",
"current_content": "false",
"option_id": "O-EN",
"audio": "ORIGINAL",
"subtitle": null,
"option_name": "original",
"id": "EN",
"desc": "Inglés",
"label_short": "Id. Inglés",
"label_large": "Idioma Original Inglés",
"intro_start_time": null,
"intro_finish_time": null,
}
]
}
}
What command should I use to extract the values related to Spanish?
(option)()
(or alternatively the XQuery 3.1 syntaxoption?*
).@
is only necessary if your input is HTML/XML.So the correct query would be
-e "$json//options/(option)()[option_id='D-ES']/content_id"
.To include the attribute names I would do:
If you really want the surrounding double quotes, you can just add them (escaped with a backslash) in the
concat()
-function......or you can use
xidel
's "Extended Strings" syntax......or use the XQuery notation for a double quote...
The output:
And finally to turn this sequence into a single line where each item is separated by a
,
:The finally command/query prettified: