Search code examples
jsonata

projection from the filtering result of an array using jsonata


I am interested in using jsonata to filter my json results, which is an array. I can use $[predicate] to filter the array, but how can I output the selected keys in each object? which means, to do project operations on each object in the result array?

Here is an example -

input:

[
  {
    "a": 1,
    "b": 2,
    "c": 3
  },
  {
    "a": 5,
    "b": 6,
    "c": 7
  }
]

expected result of selecting only a and c:

[
  {
    "a": 1,
    "c": 3
  },
  {
    "a": 5,
    "c": 7
  }
]

Solution

  • You can use this,

    $ ~> |$|{}, ['b']|
    

    here is simple demo