簡體   English   中英

使用JMESPath從JSON對象提取嵌套元素值

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

我正在嘗試使用JMESPath從JSON文檔中提取和轉換元素。 這是我的測試JSON數組:

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

我正在嘗試使用以下JMESPath表達式提取OrderNum鍵的值,但它返回null 這是我的搜索表達式:

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

為什么這不起作用?

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