0
"employees":[
 {"firstName":"John", "lastName":"Doe"}, 
 {"firstName":"Anna", "lastName":"Smith"}, 
 {"firstName":"Peter","lastName":"Jones"}
]

I know that this is a json array.
I want to do something like this:

"employees":[
 "manager":{"firstName":"John", "lastName":"Doe"}, 
 "boss1":{"firstName":"Anna", "lastName":"Smith"}, 
 "boss2":{"firstName":"Peter","lastName":"Jones"}
]

Is this json format? Is this a json array?

asked Jun 26, 2015 at 8:16

2 Answers 2

1

No, this is not JSON array, you can check it on this link https://www.jsoneditoronline.org/ just past your code on the left side, and surround it with {} , and you will see where the problem is. Also you can test JSON there in the future.

My suggestion is to use something like this.

"employees":[
 {"position":"manager", "firstName":"John", "lastName":"Doe"}, 
 {"position":"boss1", "firstName":"Anna", "lastName":"Smith"}, 
 {"position":"boss2", "firstName":"Peter","lastName":"Jones"}
]

This would be valid JSON array.

answered Jun 26, 2015 at 8:22
Sign up to request clarification or add additional context in comments.

Comments

0

If you add some { and } you can make it valid jsons, like this:

{"employees":[
 {"manager":{"firstName":"John", "lastName":"Doe"}}, 
 {"boss1":{"firstName":"Anna", "lastName":"Smith"}}, 
 {"boss2":{"firstName":"Peter","lastName":"Jones"}} 
]}

I tested it on https://www.jsoneditoronline.org/ and this is valid. Without the need to add the extra "position".

answered Jun 26, 2015 at 9:03

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.