1

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.

1 Answer 1

2

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"}}');
Sign up to request clarification or add additional context in comments.

2 Comments

yeah but when i will execute select query on this column I will receive an string but I want to receive an object.
@lakshay You should convert it into object by using json_decode() in PHP or JSON.parse() in JavaScript. Coz you cannot store anything other than string, while dealing with data from and to databases.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.