简体   繁体   中英

Extract nested element value from JSON object using JMESPath

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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