我正在使用带有jsonpath的nodejs。我有这个json结构:
{
things:{
books: [
{name: "book1"},
{name: "book2"},
{name: "book3"},
{name: "book4"},
],
movies: [
{name: "movie1"},
{name: "movie2"},
{name: "movie3"},
{name: "movie4"},
]
}
}
我想知道返回带有things
对象键名的数组的 jsonpath 表达式。那将是:
["books","movies"]
现在,我正在这样做:
Object.keys(jsonpath.eval(jsonStructure,"$.things").pop());
但我不觉得它很优雅......当我只需要键名时,我不需要获取整个结构的副本。