![](/img/trans.png)
[英]Is there a better alternative to extract nested value from Json Object
[英]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.