JSONPath - split object into array of single-member objects

66 views Asked by At

I need to convert a (flat) JSON object to an array of single-member objects:

JSON input:

{
  "field1": 123,
  "field2": 456,
  "fieldN": 789
}

Note that the number of members is variable - could be 1, could be 10.

Desired output:

[
  {"field1": 123},
  {"field2": 456},
  {"fieldN": 789}
]

Selecting every member with the JSONPath expression $.[*] gives me a flat array of the values only:

[
  123,
  456,
  789
]

I tried filtering against the "current element" via @, but it still just gives me the leaf values.

Is this even possible with JSONPath?

0

There are 0 answers