On Friday, February 12, 2016 at 11:22:29 AM UTC-5, Christopher Pisz wrote:
> Has anyone implemented an xpath equiv for json in C++?
>
> ermehgerd, it's killing me. I cannot believe there is not already some
> library that handles this.
>
> I found jsoncpp, but it crashes when you give it a path of more than 1
> level. Can't find anything else
>
My json library jsoncons has an implementation of Stefan Goessner's
JsonPath,
https://github.com/danielaparker/jsoncons/wiki/json_query. There
may be others in C++, but you're unlikely to find any json path
implementation that is as robust or industrial strength as xpath in the XML
world. Not to mention that while Stefan Goessner's JsonPath is widely used,
it doesn't have a formal specification.
An alternative would be to transform the json into an XML representation and
send it to an XPATH validator. If you have a json processor that can stream
json events, and an XPATH validator that can receive SAX events, that could
be a practical solution.
Daniel