GJSON provides a fast and simple way to search a JSON document.



name.last        >> "Anderson"
age              >> 37
children         >> ["Sara","Alex","Jack"]
children.#       >> 3
children.1       >> "Alex"
child*.2         >> "Jack"
c?ildren.0       >> "Sara"
fav\.movie       >> "Deer Hunter"
friends.#.first  >> ["Dale","Roger","Jane"]
friends.1.last   >> "Craig"

Query an array for the first match by using #(...), or find all matches with #[...]#. Queries support the ==, !=, <, <=, >, >= comparison operators and the simple pattern matching % operator.

friends.#(last=="Murphy").first   >> "Dale"
friends.#(last=="Murphy")#.first  >> ["Dale","Jane"]
friends.#(age>45)#.last           >> ["Craig","Murphy"]
friends.#(first%"D*").last        >> "Murphy"
friends.#(nets.#(=="fb"))#.first  >> ["Dale","Roger"]

Use the selectors syntax to join multiple paths into a new JSON document.


Use modifiers to modify the output.
There are three built in modifiers: @reverse, @ugly, and @pretty. Which reverse an array or the members of an object, removes all whitespace from JSON, or make the JSON more human readable, respectively.

children.@reverse                          >> ["Jack","Alex","Sara"]
children.@reverse.0                        >> "Jack"
{name.first,"murphys":friends.0}.@pretty   >> beautiful JSON
{name.first,"murphys":friends.0}.@ugly     >> compact JSON

For more information, please see the GJSON project and the GJSON syntax.

This page was built with the help of GopherJS and is open source at tidwall/gjson-play.