1

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/

1 Answers1

0

The equivalent JSONPath expression for the given jq query would be:

$.nodes[*]{"$[code]": "$[label]"}

This will produce the following output:

{
  "DE": "Germany",
  "NL": "Netherlands"
}
Daniel_Kamel
  • 610
  • 8
  • 29