Skip to content

jq module implementing JSON Pointer (RFC 6901)

License

Notifications You must be signed in to change notification settings

nichtich/jq-jsonpointer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jq-jsonpointer

Build Status

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.

Table of Contents

Install

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

Usage

See jq manual how to use jq modules in general and API description below how to use this module.

API

pointer(json_pointer)

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.

pointer_get(tokens)

Same as pointer but expects the JSON Pointer given as array of tokens:

$ jq 'include "jsonpointer"; pointer_get(["foo","0","/"]")' input.json
42

pointer_tokens

Maps a JSON Pointer string to its tokens as array of strings.

$ jq -n 'include "jsonpointer"; "/foo/0/~1" | pointer_tokens'
[
  "foo",
  "0",
  "/"
]

Contributing

The source code is hosted at https://github.com/nichtich/jq-jsonpointer.

Bug reports and feature requests are welcome!

License

Made available under the MIT License by Jakob Voß.

About

jq module implementing JSON Pointer (RFC 6901)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published