Skip to content

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 and lastname 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:

sample-json-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"
}

Codeless Reference

Retrieving Object By objectId

data_retrieving_json_data

where:

Argument                Description
table name Name of the data table from where the object is retrieved.
object id Unique identifier of the object to retrieve.
relations Name of the related property to load. For example, if table employees has a relation column homeAddress pointing to an object in the Address table, the value of the parameter would be homeAddress. The syntax allows to add relations of relations. For example, if the same Address table has a relation country pointing to the Country table, then homeAddress.country would instruct the backend to load the related Country object.
relations depth Depth of the relations to include into the response.
properties Names of the properties/columns for which  to load the corresponding values.
exclude properties Names of the properties/columns that should not be included in the response.

Returns the object containing JSON data.

Consider the following records stored in the Person data table:

data_retrieving_json_data_3

Suppose you need to retrieve one object containing JSON values. The example below retrieves the record from the data table using the object Id value.

data_retrieving_json_data_1

After the Codeless logic runs, the server returns the object containing JSON values.

data_retrieving_json_data_2

Retrieving Multiple Objects

Consider the following records stored in the Person data table:

data_retrieving_json_data_3

Suppose you need to retrieve objects from the data table containing "New York" value in the "city" property and values greater than 20 in the "age" property. To achieve this, you need to use the following where clause condition:

profile->'$.age' > 20 and profile->'$.address.city' = 'New York'

For more information about retrieving objects using the where clause condition, refer to the JSON Query documentation.

The example below finds objects matching the where clause condition presented above.

data_retrieving_json_data_5

Important

For a detailed description of all input parameters see the Basic Object Retrieval topic of this guide.

After the Codeless logic runs, the operation returns two objects matching the specified where clause condition:

data_retrieving_json_data_4