Skip to content

Saving JSON Data

It is important to understand that JSON data in Backendless database are values stored in regular database objects. In order to take advantage of the JSON-specific APIs, the values must be stored in database column of the JSON type. Read how to create JSON columns. To add JSON data to the database, you can use either API or Backendless Console.

API

To store JSON with the API, you need to use the API to store single or multiple objects. Consider the following JSON document/object:

{
    "name" : "Joe",
    "age" : 34,
    "address" : {
      "street" : "123 Main St",
      "city" : "New York",
      "state": "New York"
    },
    "favoriteNumbers": [ 5,7,9,21,100 ],
    "favoriteColors": [ "Blue", "Green" ]
}

The object includes another object (the "address" property), a property containing an array of numbers ("favoriteNumbers") and a property containing an array of string values ("favoriteColors"). The JSON object will be saved in the Person table in the profile column using the following request:

Request/Endpoint:

POST https://api.backendless.com/APP-ID/REST-API-KEY/data/Person 

Request header:

Content-Type:application/json

Request body:

{
  "profile" : {
    "name" : "Joe",
    "age" : 34,
    "address" : {
      "street" : "123 Main St",
      "city" : "New York",
      "state": "New York"
    },
    "favoriteNumbers": [ 5,7,9,21,100 ],
    "favoriteColors": [ "Blue", "Green" ]
  }
}

Response:

{
  "___class": "Person",
  "ownerId": null,
  "updated": null,
  "created": 1597165292000,
  "objectId": "553C19C2-988D-47FA-9BF2-EC4AE6C91CFE",
  "profile": {
    "age": 34,
    "name": "Joe",
    "address": {
      "city": "New York",
      "state": "New York",
      "street": "123 Main St"
    },
    "favoriteColors": [ "Blue", "Green" ],
    "favoriteNumbers": [ 5,7,9,21,100 ]
  }
}

Backendless Console

JSON data can be added to your objects manually. Make sure to declare a JSON column in your database first. To add a JSON value, use the DATA BROWSER screen. You can work with the values in JSON columns as with plain text, however, entered value must be valid JSON. The database supports JSON string, number, object, array or null values.