0

I want to map a key "coordinate" to an object with two key-value pairs which are a key of "latitude" mapping to the integer 50 and a key "longitude" mapping to the integer 60.

"coordinate" : [{
    "latitude": 50, "longitude": 60
}]

My question is this the correct way to set up an object in JSON in JavaScript because I keep getting error or typo at "coordinate"?

4
  • 4
    It's an array containing an object. Remove the [ ] if you want only an object Commented Oct 29, 2018 at 15:05
  • 1
    But what's the error? Knowing what "an error" is would be helpful Commented Oct 29, 2018 at 15:07
  • 2
    JSON is a serialzation format, a String. You have Objects (in whatever language you're using) and you serialize them into a JSON (-string) Commented Oct 29, 2018 at 15:09
  • 1
    I found the error. You were right I need to remove the [ ]. Commented Oct 29, 2018 at 15:10

1 Answer 1

1

You can make use of the below code to initialize the key value pair in object

var sampleObject = {"coordinate" : [{
    "latitude": 50, "longitude": 60
}]}

console.log(sampleObject)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.