将JSONPath转换回JSON对象[Javascript]

时间:2019-06-20 04:21:45

标签: javascript json jsonpath

使用NPM:jsonpath从JSON对象获取所有与pathExpression匹配的JSONPath。

类似“ jp.nodes(obj,pathExpression)”的东西。有没有一种方法可以从pathExpression的JSON对象构造出JSON对象,并根据该路径将该值放回去?

var nodes = jp.nodes(data, '$..author');

 [
   { path: ['$', 'store', 'book', 0, 'author'], value: 'Nigel Rees'},
   { path: ['$', 'store', 'book', 1, 'author'], value: 'Evelyn' },
   { path: ['$', 'store', 'book', 2, 'author'], value: 'Herman' }
 ]

After some computation i need to reverse map the path's and the value back to the JSON Object.

0 个答案:

没有答案