JSON Path

Using JSON Paths, you can use specific rules to extract precise data from your JSON record, instead of extracting the entire JSON dump.

JSON Paths can be used to extract a part of JSON, filter specific items conditionally from an array of objects. You can use JSON Paths with the Read Bins API.

Syntax

Syntax of JSON Path & Examples are based on Stefan Goessner's post introducing JSONPath.

JSON Path Description
$ The root object/element
@ The current object/element
. Child member operator
.. Recursive descendant operator; JSONPath borrows this syntax from E4X
* Wildcard matching all objects/elements regardless their names
[] Subscript operator
[,] Union operator for alternate names or array indices as a set
[start:end:step] Array slice operator borrowed from ES4 / Python
?() Applies a filter (script) expression via static evaluation
() Script expression via static evaluation

Sample Data

{
  "moduleAccess": {
    "users": [ 
      {
        "id": "1",
        "firstName": "Nigel",
        "lastName": "Rees",
        "age": 23,
        "gender": "male",
        "country": "Australia"
      }, 
      {
        "id": "2",
        "firstName": "Evelyn",
        "lastName": "Waugh",
        "age": 28,
        "gender": "female",
        "country": "Indonesia"
      },
      {
        "id": "3",
        "firstName": "Michelle",
        "lastName": "White",
        "age": 27,
        "gender": "female",
        "country": "Spain"
      },
      {
        "id": "4",
        "firstName": "Aaron",
        "lastName": "Fernandes",
        "age": 22,
        "gender": "male",
        "country": "India"
      }
    ],
    "userPermissions": {
      "createGrant": true,
      "editGrant": false
    }
  }
}

Data Access Examples

JSON Path Description
$.moduleAccess.users[*].firstName The firstName of all users in the module
$..country All countries
$.moduleAccess.* All entries in moduleAccess, which are users and userPermissions
$.moduleAccess..age Extract age of all the users
$..users[2] The third user
$..users[(@.length-1)] The last user via script subscript
$..users[-1:] The last user via slice
$..users[0,1] The first two users via subscript union
$..users[:2] The first two users via subscript array slice
$..users[?(@.age)] Filter all users with age
$..users[?(@.age<25)] Filter all users whose age is lesser than 25 years.
$..users[?(@.age==27)] Filter all users whose age is 27
$..users[?(@.age<25 && @.country=="Australia")] Filter all Autstralian users whose age is lesser than 25
$..* All members of JSON structure

Create a Free Account

Create an Account View Pricing