0

I'm trying to insert an array of strings in JSON but it isn't working.

json:

{
    "1": [{
        "id": "1",
        "title": "test 1",
        "galery": { "http://placehold.it/540x540" , "http://placehold.it/540x520"}
    }]
}

It's returning me syntax error on "galery" line but I can't figure out what is it

4 Answers 4

2

For an array, use:

"galery": ["http://placehold.it/540x540", "http://placehold.it/540x520"]

For named properties, use something like:

"galery": { url1:"http://placehold.it/540x540", url2:"http://placehold.it/540x520" }
Sign up to request clarification or add additional context in comments.

Comments

2

Use [ ] for array of images in gallery. { } will expect object (key/value pairs).

You can check valid JSON syntax at http://www.json.org/

Comments

1

Replace the braces with brackets.

{
"1": [{
    "id": "1",
    "title": "test 1",
    "galery": [ "http://placehold.it/540x540" , "http://placehold.it/540x520" ]
}]
}

Comments

0

You have incorrect syntax at two places. Below is the correct one:

{
"1": {
    "id": "1",
    "title": "test 1",
    "galery": ["http://placehold.it/540x540" , "http://placehold.it/540x520"]
}

}

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.