Link Search Menu Expand Document

JSONPath Cheat Sheet


Depending on the client used JSONPath expressions do start with $. indicating the root element. Some clients omit the leading $..

 $[0].title      [0].title                # With implicit "$."
 $['store']['book'][0]['title']     # Alternative notation similar to scripting languages

Tree Traversal

 $.parentNode.childNode.field       # XPath: /parentNode/childNode/@field (content of "field" of all "childNode"s of "parentNode")
 $..anyChildNode                    # XPath: //anyChildNode (all children at any depth named "anyChildNode"
 $.parentNode.*                     # XPath: /parentNode/* (all children below)

Array Access

 $.myList[0]            # first element
 $.myList[-1]           # last element
 $.myList[2:3]          # range
 $.myList[0,4,5]        # selection


 $.customer[?(]                      # Only "customer"s that have attribute "car"
 $.customer[?( == 'Ford Fiesta')]     # Only "customer"s with "Ford Fiesta"s
 $.customer[?(@.age > 18)]                 # Only adults

Complex Conditions

 $.customer[?(@.age > 18 || == 'Ford Fiesta')]     # logical or
 $.customer[?(@.age < 18 && @.hobby == 'Biking' )]       # logical and

Output Mapping

 $.[].{Name:name, Age:age, Hobbies:details.hobbies}        # Mapping fields/nested fields to new set
Related jq