Re:Specifying JSON
by andyjohnson0 on Thursday May 19, 2016 @11:21AM
(#11730888)
Is there an equivalent of xpath for searching/traversing in-memory js object graphs?
[ Parent
| on HN ]
Re:Specifying JSON
by kisstheblade on Thursday May 19, 2016 @01:17PM
(#11731786)
Jsonpath, eg. https://github.com/jayway/JsonPath
you can use chained map/reduce.
object.listOfItems .reduce((item) => item.type === 'car') .map((item) => item.name));
This is way more powerful than xpath.
Hi, I think that instead of "reduce((item) => item.type === 'car')" you actually meant "filter((item) => item.type === 'car')".
What about things like axes in XPath?
Sometimes all you need is printf, not direct memory access to the character byte array.
There's JMESPath: http://jmespath.org/