Use the Transform operator to remove one or more key/value pairs from an Object?

2k Views Asked by At

JSONata newbie checking in. I have reviewed all the questions in this forum and cannot find the answer so am asking here.

Given this source...

{
  "Price": 34.45,
  "Product Name": "Bowler Hat",
  "ProductID": 858383,
  "Quantity": 2,
  "SKU": "0406654608"
}

I would like to reduce it to...

{
  "Product Name": "Bowler Hat",
  "ProductID": 858383,
  "SKU": "0406654608"
}

...using the Transform operator to delete Price and Quantity. I've tried various permutations of this...

$ ~> |*|{}, ['Price', 'Quantity']|

..but am not getting the result I am looking for. Here is an Exerciser link.

Thanks in advance for any assistance.

1

There are 1 best solutions below

0
On

Just a small modification needed - the 'matching' clause needs to match the object that you wish to modify, in your case it is the context item '$'. The wildcard '*' is going to return the sequence of values in that object rather than the object itself. So your expression should be:

$ ~> |$|{}, ['Price', 'Quantity']|

See https://try.jsonata.org/qUwOtT-pt