Getting basic values
DQL uses location path syntax to extract values from JSON structures. The following examples demonstrate several examples of getting basic values from JSON data.
Contents
- Example JSON
- Get a top-level field
- Get a nested field
- Get an entire object
- Select a specific index in an array
- Select an entire array
- Return one field of every object in an array
- Return fields that contain special characters in the key name
- Get the number of elements in the list
Example JSON
The examples below use this JSON data:
{
"name": "John Smith",
"address": {
"street": "123 Park Avenue",
"city": "Atlanta",
"state": "GA",
"zip": "12345"
},
"phones": [
{
"type": "Home",
"number": "123-456-7890"
},
{
"type": "Cell",
"number": "098-765-4321"
}
],
"display name": "myuser123"
}
Get a top-level field
To access a top-level field with DQL, enter the field's name.
DQL
name
Result
"John Smith"
Get a nested field
To access fields below the top level, use field names separated by dot . delimiters.
DQL
address.city
Result
"Atlanta"
Get an entire object
Enter the name of an object in the JSON file to retrieve all the data within that object.
DQL
address
Result
{
street: '123 Park Avenue',
city: 'Atlanta',
state: 'GA',
zip: '12345',
}
Select a specific index in an array
To access individual values in an array in a JSON file, specify an index number between square brackets after the array's name.
DQL
phones[0].number
Result
"123-456-7890"
Select an entire array
Enter the name of an array in the JSON file to retrieve all the data within that array.
DQL
phones
Result
[
{
"type": "Home",
"number": "123-456-7890"
},
{
"type": "Cell",
"number": "098-765-4321"
}
]
Return one field of every object in an array
To return a specific field from multiple objects in an array, enter the array's name then the field's name, separated by a dot.
DQL
phones.number
Result
["123-456-7890","098-765-4321"]
Return fields that contain special characters in an array
If a field in the JSON file contains special characters (like spaces), put the field's name in single quotes.
DQL
'display name'
Result
myuser123
Get the number of elements in the list
DQL
$count(phones)
Result
2