JSON DataType

I never used this data type in backendless before I believe it is recently added.
I appreciate if someone helps me out how to use this data type i mean I can create JSON in my app and i don’t know how can I upload the JSON to backendless under JSON data type?

Hi, @Saad_Zahoor2

Yes, this is the new feature. We will update the docs and all SDK soon.

First you have to describe your column as JSON-type and then save a JSON to the database like that (my example is in javascript):

Backendless.Data.of('yourTable').save({
       myJson: {
        'letter'     : 'a',
        'number'     : 10,
        'decimals'   : [12.3, 43.28, 56.89],
        'colours'    : ['red', 'green', 'blue'],
        'description': 'It is an "Example".',
        'timeMarks'  : {
          'time'     : '12:18:29.000000',
          'date'     : '2015-07-29',
          'date_time': '2015-07-29 12:18:29.000000'
        }
      }
    })

Regards,
Igor

Thank you for your time @Ignor

I am using java in android studios

    Backendless.Data.of( "PassengerChauffeurConnection" ).update(whereClause,
            update, new AsyncCallback<Integer>() {
                @Override
                public void handleResponse(Integer response) {


                }

                @Override
                public void handleFault(BackendlessFault fault) {

                }
            });

i am updating the existing table
Can you help me how can define the json and pass it to backendless api, a simple example is fine just 1 key-value pair

update in the code is represent a map

The JSON type can be presented with Map or List types which are converted to json-object or json-array respectively.
Inside the map or list you can use other Maps or Lists, or values which are represent json “primitive” types: string, boolean, null, int, double

Thank @oleg-vyalyh for looking into my case

Can you guide me how can I pass the JSON data type to Backendless API

    Map<String , Object> sendingDetails = new HashMap<>();

        sendingDetails.put("actualFare" , actualFare );
        sendingDetails.put("howMuchPassengerPaid" ,doPassengerPaid );
  ObjectMapper objectMapper = new ObjectMapper();
        String json = null ;
        try {
            json = objectMapper.writeValueAsString(sendingDetails);

        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }

        String whereClause = Constants.TOKEN +" = " + sharedPreferencesAfterRideStart.getInt(App.GET_TOKEN , 0);

        Backendless.Data.of( "PassengerChauffeurConnection" ).update(whereClause,
                json, new AsyncCallback<Integer>() {
                    @Override
                    public void handleResponse(Integer response) {


                    }

                    @Override
                    public void handleFault(BackendlessFault fault) {

                    }
                });

when i pass JSON it gives me an error, of course, it requires MAP object

Please, show your table structure.

Here is an example of how to save objects into backendless database.

    HashMap<String, Object> yourEntity = new HashMap<>();
    yourEntity.put( "columnNameWithString", "string_value" );
    yourEntity.put( "columnNameWithBoolean", true );
    yourEntity.put( "columnNameWithInteger", 10 );
    yourEntity.put( "columnNameWithJSON", <your_json_object> );

    Backendless.Data.of( "tableName" ).save(yourEntity);

Also i said before, the JSON accept Map or List, so you do not need to convert it to String.

1 Like

To get specific value from the JSON document or specific subtree of the document use the syntax like:

    DataQueryBuilder dataQueryBuilder = DataQueryBuilder.create()
            .addProperty( "jsonColumnName -> '$.jsonPath' as myValue" )
            .addProperty( "jsonColumnName -> '$.nameOfValue' as mySubtree" );

    Backendless.Data.of( "tableName" ).find(dataQueryBuilder)

Thank you this is what i am/was looking for !!