Extract nested element value from JSON object using JMESPath

删除回忆录丶 提交于 2019-12-25 00:46:08

问题


I am trying to extract and transform elements from a JSON document using JMESPath. Here is my test JSON array:

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. Here is my search expression:

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

Why is this not working?


回答1:


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

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


来源:https://stackoverflow.com/questions/51715463/extract-nested-element-value-from-json-object-using-jmespath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!