Ramon Vasconcelos
Ramon Vasconcelos

Reputation: 945

JSON array returns syntax error

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

Upvotes: 0

Views: 276

Answers (4)

TheLittleHawk
TheLittleHawk

Reputation: 628

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

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

Upvotes: 2

Sandeep Solanki
Sandeep Solanki

Reputation: 51

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"]
}

}

Upvotes: 0

Dimitri
Dimitri

Reputation: 1208

Replace the braces with brackets.

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

Upvotes: 1

ne1410s
ne1410s

Reputation: 7082

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

Upvotes: 2

Related Questions