Filter multiple fields in only one JSONPath expression

Given the following input JSON:

{
  "a": 1,
  "b": "some root string",
  "c":
  {
    "d": "some inner string"
  }
  "e": "ignored field"
}

Is it possible to obtain the following JSON using a JSONPath expression?

{
  "a": 1,
  "b": "some root string",
  "d": "some inner string"
}

Thank you in advance.

Upvotes: 3

Views: 6451

Answers (1)

Akshay G
Akshay G

Reputation: 2280

Below JsonPath should give you the expected output. However it depends on the type of Implementation.

$..['a','b','d']

JSONPath Evaluator : https://jsonpath.herokuapp.com/

Jayway JsonPath

You need to set the option Return null for missing leaf

enter image description here

Stefan Goessner JsonPath

It returns all the values without having to select any options.

enter image description here

Upvotes: 2

Related Questions