The following examples show how to use FQL to return structured data from JSON data.
The examples below use this JSON data:
{
"name": "John Smith",
"physical_address": {
"street": "123 Park Avenue",
"city": "Atlanta",
"state": "GA",
"zip": "12345"
},
"work_address": {
"street": "583 W. Island Drive",
"city": "Miami",
"state": "FL",
"zip": "44456"
},
"mailing_address": {
"street": "232 Ravensburg Road",
"city": "Durham",
"state": "NC",
"zip": "03948"
},
"phones": [
{
"type": "Home",
"number": "123-456-7890"
},
{
"type": "Cell",
"number": "098-765-4321"
},
{
"type": "Cell",
"number": "888-777-5555"
},
{
"type": "work",
"number": "314-265-9078"
}
]
}
The example below returns three objects as an array.
FQL | [physical_address, work_address, mailing_address] |
Result |
[ {"street": "123 Park Avenue","city": "Atlanta","state": "GA","zip": "12345"}, {"street": "583 W. Island Drive","city": "Miami","state": "FL","zip": "44456" }, {"street": "232 Ravensburg Road","city": "Durham","state": "NC","zip": "03948"} ] |
The example below gets the values of the city
key from three objects and returns the values as an array.
FQL | [physical_address, work_address, mailing_address].city |
Result | ["Atlanta","Miami","Durham"] |
FQL can return an array of key-value pairs composed of values from an object. The example below gets the values of the type
and number
keys from objects in the phones
array and returns them as an array of key-value pairs.
FQL | phones.{type: number} |
Result |
[ {"Home": "123-456-7890"}, {"Cell": "098-765-4321"}, {"Cell": "888-777-5555"}, {"work": "314-265-9078"} ] |
FQL can return an object with key-value pairs composed of values from an object. Group returned values in an array if they have the same key name in their respective objects. The example below groups the values of Cell
keys from two different objects in the phones
array.
FQL | phones{type: number[]} |
Result |
{ "Home": ["123-456-7890"], "Cell": ["098-765-4321","888-777-5555"], "work": ["314-265-9078"] } |
Last modified: 2024/06/05
Additional resources
Videos
Blog posts