JSONPath-Plus / JSONPath

A fork of JSONPath from http://goessner.net/articles/JsonPath/
Other
963 stars 169 forks source link

Return as object with key and value of match. #153

Open dionsnoeijen opened 3 years ago

dionsnoeijen commented 3 years ago

With this json:

{
  "firstName": "John",
  "lastName" : "doe",
  "age"      : 26,
  "address"  : {
    "streetAddress": "naist street",
    "city"         : "Nara",
    "postalCode"   : "630-0192"
  },
  "phoneNumbers": [
    {
      "type"  : "iPhone",
      "number": "0123-4567-8888",
      "other" : "value"
    },
    {
      "type"  : "home",
      "number": "0123-4567-8910",
      "other" : "value"
    }
  ]
}

A query like this: $.phoneNumbers.[type,number] returns:

[
  "iPhone",
  "0123-4567-8888",
  "home",
  "0123-4567-8910"
]

It would be very helpful if there is an option to make the result as this:

[
    {"type": "IPhone", "number": "0123-4567-8888"},
    {"type": "home", "number": "0123-4567-8910"}
]
callumgare commented 1 year ago

I would also love this! There is already a syntax that is used by a couple of other parses so I think it makes most sense to use that syntax: https://cburgmer.github.io/json-path-comparison/results/parens_notation.html