Retrieving JSON Data¶
JSON values are stored in database columns of type JSON
. The data retrieval mechanism for JSON values is the same as for any other data stored in Backendless database. You can use the data retrieval API to retrieve objects from the Backendless database. Data in the JSON
columns is returned as plain JSON.. Consider the example below:
Suppose the database stores objects in the Person
data table. The table declares the profile
column of type JSON. The column contains JSON values in the following format:
{
"age": 55,
"name": "Bob",
"address": {
"city": "Los Angeles",
"state": "California",
"street": "123 Santa Monica Blvd."
},
"lastname": "Smith",
"favoriteColors": [
"Blue", "Red"
],
"favoriteNumbers": [
13, 21, 88
]
}
As you can see the sample JSON value above exhibits the following "qualities":
- literal string and numeric values -
age
,name
andlastname
keys. - an array consisting of strings -
favoriteColors
- an array consisting of numbers -
favoriteNumbers
- an enclosed JSON object in the
address
key.
The JSON values and the Person objects may appear as shown below in the database:
Suppose the client application needs to retrieve both Person
objects and the corresponding profile
values . This can be accomplished with the following request:
Request/Endpoint:
GET https://api.backendless.com/APP-ID/REST-API-KEY/data/Person/1316FEE4-92A6-4400-9D08-EB243BF57671
Request header:
none
Request body:
none
The request produces the following response:
{
"created":1598395155000,
"profile":{
"age":55,
"name":"Bob",
"address":{
"city":"Los Angeles",
"state":"California",
"street":"123 Santa Monica Blvd."
},
"lastname":"Smith",
"favoriteColors":[
"Blue",
"Red"
],
"favoriteNumbers":[
13,
21,
88
]
},
"___class":"Person",
"ownerId":null,
"updated":1598913281000,
"objectId":"1316FEE4-92A6-4400-9D08-EB243BF57671"
}