简体   繁体   English

使用JMESPath从JSON对象提取嵌套元素值

[英]Extract nested element value from JSON object using JMESPath

I am trying to extract and transform elements from a JSON document using JMESPath . 我正在尝试使用JMESPath从JSON文档中提取和转换元素。 Here is my test JSON array: 这是我的测试JSON数组:

const search = jmespath.search;
const testData =
{
"ServiceAccount": [
    {
        "Type": "WIDGET",
        "ID": [
            {
                "OrderNum": "12345",
                "OrderTyp": "ABDCD"
            }
        ]
      }
    ]
};

I am trying to extract the value of the OrderNum key using the following JMESPath expression, but it returns null . 我正在尝试使用以下JMESPath表达式提取OrderNum键的值,但它返回null Here is my search expression: 这是我的搜索表达式:

const result = search(testData, 'ServiceAccount.ID.OrderNum');
console.log(result);

Why is this not working? 为什么这不起作用?

const testData =
{
"ServiceAccount": [
    {
        "Type": "WIDGET",
        "ID": [
            {
                "OrderNum": "12345",
                "OrderTyp": "ABDCD"
            }
        ]
      }
    ]
};

const result = jmespath.search(testData, 'ServiceAccount[].ID[].OrderNum');
console.log(result);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM