With jq
I can use add
to combine results. I am looking for the jsonpath
equivalent of this:
$ json="{\"nodes\": [{\"code\": \"DE\", \"label\": \"Germany\", \"ignore\": \"i1\"}, {\"code\": \"NL\", \"label\": \"Netherlands\", \"ignore\": \"i2\"}]}"
$ echo $json | jq '[.nodes[] | {(.code): (.label)}] | add'
{
"DE": "Germany",
"NL": "Netherlands"
}
Best I can up with is $..nodes.[*].[code,label]
. However, this returns:
["DE",
"Germany",
"NL",
"Netherlands"]
I am trying this website: https://jsonpath.com/
The equivalent JSONPath expression for the given jq query would be:
This will produce the following output: