首页 > 解决方案 > 使用 Transform 运算符从对象中删除一个或多个键/值对?

问题描述

JSONata 新手签到。我已经查看了这个论坛中的所有问题,但找不到答案,所以在这里问。

鉴于此来源...

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

我想减少到...

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

...使用Transform运算符删除价格和数量。我已经尝试过这个的各种排列...

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

..但没有得到我正在寻找的结果。是一个锻炼者链接。

提前感谢您的任何帮助。

标签: jsonata

解决方案


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


推荐阅读