FunctionSource, Your Source for Developer News

JSON Pointer

Posted by Dion Almaer about a year ago on json

I love a “spec” that fits on a couple of pages, and (especially if you take out the boiler plate) Kris Zyp and Paul Bryan have done that with JSON Pointer. The example says it all:

For the following JSON representation:
{
"foo": {
"anArray": [
{ "prop": 44 }
],
"another prop": {
"baz": "A string"
}
}
}
The following JSON Pointers would be resolved:JSON Pointer             resolution
-----------------------------------
/                        self, the root of the resource itself
/foo                     the object referred to by the foo property
/foo/another%20prop      the object referred to by the "another prop"
property of the object referred to by the
"foo" property
/foo/another%20prop/baz  the string referred to by the value of "baz"
property of the "another prop" property of
the object referred to by the "foo" property
/foo/anArray/0           the first object in the "anArray" array

Note how simple it is. You don’t see anything as fancy as XPath. No double-slashes and beyond.

If you are working with a JSON data store

https://github.com/janl/node-jsonpointer

http://somehost/somedoc.json#/foo/bar