3

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
  }
]

1 Answer 1

1

You can use this,

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

here is simple demo

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it works. Two follow ups, firstly is the any document that explains the operators used in this example; Secondly, this doesn't seem graceful since it's by remove instead of select, what if I have so many keys, and I want to select a few specific keys? should I list all the keys that should be removed? Thanks.
1) docs.jsonata.org/other-operators 2) $.{ 'a': a, 'b': b }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.