1.9.07 # JSONPath - XPath for JSON

Here and there on the web we can find a discussion or solution for something like XPath for JSON. Despite the fact, that JSON structures can be processed by the C family of programming languages quite easily, there should be a benefit in having some kind of XPath4JSON.

So I was thinking about a suitable path expression syntax for addressing portions of any JSON structure. Those path expressions should

  • be naturally based on C language family characteristics.
  • cover only essential parts of XPath 1.0.

As a result here is JSONPath, wich is a dual thing. Primarily JSONPath is a path expression syntax, which can select parts of JSON structures in the same way as XPath expressions select nodes of XML documents. Such an expression may look like

$..book[2].title

and is quite similar to its XPath counterpart

//book[3]/title

Currently there is a small set of nine JSONPath syntax elements, which allows the construction of sophisticated path expressions.

Furthermore JSONPath is a lightweight tool implemented in Javascript and PHP for accessing JSON structures on the client and the server.

You can download

  • jsonpath.js
  • jsonpath.php

for free and read more about it.

Update:

Atif Aziz came up with a C# port of JSONPath in a very short time (jsonpath.cs). Thanks for that.

JSON XPath Javascript PHP C#

Labels: Javascript, JSON, PHP, XPath

3 comments
gipoco.com is neither affiliated with the authors of this page nor responsible for its contents. This is a safe-cache copy of the original web site.