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?

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.

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".

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.