Json Operators

If you have a json and you want to access value of any attribute of it, than it is not directly accessible with dot operator(.), for that you have to use jsonGet() method.

It takes two arguments both are required.

Argument 1 : The entire json (on digia dashboard you can access it through "response.body"

Argument 2 : The value you want to access from the json.

Let's understand it through an example.

//dummy json
{
   "users": [
      {
         "id": 1,
         "name": "Alice"
      },
      {
         "id": 2,
         "name": "Bob"
      }
   ]
}

If you want to access value of "id" for first element in users array. Than we can write something like this.

// Some code
jsonGet(response.data, 'users[0].id');

//Note: the second argument is always surrounded by single quotes.
//response.data : entire json data
// users[0].id : value which you want to access from json.
// It will give us a value which is 1

Last updated