Hi everyone,
We’ve finally come to the last part of our JSON series. Catch up with the rest of the articles here.
Wildcards in JSON
Like we do for Programming Languages, we have a character that we can replace it with. This will fetch all the output , which is a good idea when we don’t know the specific outputs.
So lets go with our same previous example:
So , here’s what happened. Here I want to know the details of my parents which is in an array with the key ‘Parents’. But I wanted only the specific details (just the name).The star operator ‘*’ iterates through the array and fetches just the name of all the objects present inside it and returns that as an Array. As simple as that :)
Note that all outputs of the query come as an Array.
Manipulation on Lists:
If you are familiar with operations on List , then this is just the same concept that’s used. Here, this List contains numbers from 0 to 10, ie 11 values. The first index is 0 and its value , for the sake of simplicity has been kept 0. The last index is 10, its value is 10.
Here is the List:
(i)Query to fetch the first 3 elements .
Note that the value after the colon indicates the number of values(not index)to be fetched . Hence, for index, the effective query would be for index [0:2] ie [0,1,2]
(ii)Query to fetch all values in list
(iii) Query to fetch alternate values
Here the 3rd value(2) is the number of hops it should take to fetch the next value. By default , it is 1 .
(iv)Query to fetch the last value
Here , we can assume that the last value to be of index -1, second last value to be -2 …You get the gist.
And that’s that. This is all we need to know for the Basics.
Until next article :)