我目前遇到的问题是,当我选择带有JSONPath的所需节点时,我无法从给定的节点创建“sub-json”。
假设我有以下JSON(从JSONPath GitHub中提取):
{
"store": {
"book": [
{
"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{
"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{
"category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 19.95
}
},
"expensive": 10
}
使用以下JSONPath表达式,我可以提取自行车属性:
$.store.bicycle
输出:
[
{
"color":"red",
"price":19.95
}
]
我真正想要的是创建一个新的JSON,只包括我用JSONPath声明的节点,如:
{
"store": {
"bicycle": {
"color": "red",
"price": 19.95
}
}
}
我无法使用JSOnPath访问父节点名称,我只获取值。我也不想解析JSONPath表达式来创建JSON(即通过“。”拆分表达式)。 我怎样才能做到这一点?