abhit
abhit

Reputation: 981

How to insert a javascript object into sqlite database?

I have a javascript object as :

service location : Object
   formatted_address:"Jharkhand, India"
   latitude : "23.6101808"
   longitude :"85.2799354"

How can I insert this in a single column as object in my sqlite database.

I want to receive this column value as an object in my response when I execute SELECT query on my database.

Upvotes: 1

Views: 1181

Answers (1)

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167172

You can convert it into JSON String and send it.

JSON.stringify({
  service_location: {
    formatted_address: "Jharkhand, India",
    latitude: "23.6101808",
    longitude: "85.2799354"
  }
});

This will be converted into:

{"service_location":{"formatted_address":"Jharkhand, India","latitude":"23.6101808","longitude":"85.2799354"}}

And this can be safely decoded using:

JSON.parse('{"service_location":{"formatted_address":"Jharkhand, India","latitude":"23.6101808","longitude":"85.2799354"}}');

Upvotes: 2

Related Questions