使用 JsonPath - 如何根据另一个对象中的字段名称获取一个对象的属性子集(Jayway)

问题描述 投票:0回答:1

给定一个对象(“includeFields”),指定应将另一个对象(“toBeFiltered”)的哪些属性提取到新的结果对象中:

{
  "toBeFiltered": {
    "a": "AAA",    
    "b": "BBB",    // Excluded from the result as "includeFields" doesn't include "b"
    "c": "CCC"     
  },
  "includeFields": {
    "a": true,
    "c": true 
  } 
}

何时:一些 JsonPath 表达式检查“toBeFiltered”中的哪些字段名称也出现在“includeFields”中

然后:

{
  "a": "AAA",
  "c": "CCC"
}

是否可以使用 JsonPath 执行此操作?如果可以 - JsonPath (Jayway) 表达式会是什么样子?

json jsonpath jayway
1个回答
0
投票

JSON Path 不会执行这样的转换。这只是一个查询语法:它只会告诉您项目是否以及在哪里。

还有其他语法可以做到这一点,例如JMESPath,它很大程度上基于 JSON Path。

© www.soinside.com 2019 - 2024. All rights reserved.