使用JMESPath从JSON对象提取嵌套元素值 [英] Extract nested element value from JSON object using JMESPath
本文介绍了使用JMESPath从JSON对象提取嵌套元素值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用JMESPath
从JSON文档中提取和转换元素.这是我的测试JSON数组:
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"
}
]
}
]
};
我试图使用以下JMESPath表达式提取OrderNum
键的值,但它返回null
.这是我的搜索表达式:
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);
为什么这不起作用?
推荐答案
const testData =
{
"ServiceAccount": [
{
"Type": "WIDGET",
"ID": [
{
"OrderNum": "12345",
"OrderTyp": "ABDCD"
}
]
}
]
};
const result = jmespath.search(testData, 'ServiceAccount[].ID[].OrderNum');
console.log(result);
这篇关于使用JMESPath从JSON对象提取嵌套元素值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文