jq module implementing JSON Pointer (RFC 6901)
This git repository contains an implementation of JSON Pointer (RFC 6901) as module for the jq data transformation language.
Installation requires jq version 1.5 or newer.
Put jsonpointer.jq
to a place where jq can find it as module.
One way to do so is to download the current version of the file:
mkdir -p ~/.jq && git clone https://github.com/nichtich/jq-jsonpointer.git ~/.jq/jsonpointer
Or check out this repository to directory ~/.jq/jsonpointer/
:
mkdir -p ~/.jq && wget -N https://github.com/nichtich/jsonpointer/raw/master/jsonpointer.jq
See jq manual how to use jq modules in general and API description below how to use this module.
Returns a filter compiled from a given JSON Pointer. For instance given a JSON file input.json
:
{"foo":[{"/":42}]}
The value 42
can be accessed with JSON Pointer syntax like this:
$ jq 'include "jsonpointer"; pointer("/foo/0/~1")' input.json
42
Character -
to index the (nonexisting) member after the last array element is
not supported. If the JSON Pointer does not correspond to an existing element,
the filter returns null
instead of throwing an error.
Same as pointer but expects the JSON Pointer given as array of tokens:
$ jq 'include "jsonpointer"; pointer_get(["foo","0","/"]")' input.json
42
Maps a JSON Pointer string to its tokens as array of strings.
$ jq -n 'include "jsonpointer"; "/foo/0/~1" | pointer_tokens'
[
"foo",
"0",
"/"
]
The source code is hosted at https://github.com/nichtich/jq-jsonpointer.
Bug reports and feature requests are welcome!
Made available under the MIT License by Jakob Voß.