PLAYGROUND

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

EXAMPLES

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.

{name.first,age,"murphys":friends.#(last="Murphy")#.first}
[name.first,age,children.0]

Use modifiers to modify the json. There are currently the following built-in modifiers:

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
[@this].#(age>35).name.last                >> "Anderson"

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



This page is open source at tidwall/gjson-play.