Reputation: 6976
I am trying to build a JSON object that will drive my web app, however I currently getting an invalid JSON object returned and I cannot see the problem,
I have run the JSON through JSON Lint and I am getting the following error,
Parse error on line 19: ... ] },
----------------------^ Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['
My JSON object is below,
{
"name": "FF",
"good": {
"doors" : [
{
"name" : "Door Name 1",
"thumb": "http://placehold.it/134x134/ff0000/ffffff",
"specifics" : [
"Specifics 1a",
"Specifics 2a"
]
},
{
"name" : "Door Name 2",
"thumb": "http://placehold.it/134x134/b4da55/ffffff",
"specifics" : [
"Specifics 1b",
"Specifics 2b",
"Specifics 3b",
]
}, //LINE 19 - Where the JSON Lint states there to be an error.
{
"name" : "Door Name 3",
"thumb": "http://placehold.it/134x134/0000ff/ffffff",
"specifics" : [
"Specifics 1c",
"Specifics 2c",
"Specifics 3c",
"Specifics 4c"
]
},
],
"walls" : [
{
"name" : "Chair Rail A",
"thumb": "http://placehold.it/134x134/0000ff/ffffff",
"specifics" : [
"Chair Rail A",
]
},
{
"name" : "Wall Paneling with Rosettes A",
"thumb": "http://placehold.it/134x134/b4da55/ffffff",
"specifics" : [
"Panel Moulding A",
"4\" Rossette"
]
},
{
"name" : "Wall Paneling with Rossettes B",
"thumb": "http://placehold.it/134x134/ff0000/ffffff",
"specifics" : [
"Panel Moulding A",
"6\" Rossette"
]
},
],
},
"best": {},
"better": {}
}
I assume that problem is coming from trying to have an array in object so I can have multiple options when looping, is this correct? And if so how should my JSON be formed?
Upvotes: 0
Views: 3713
Reputation: 126
The problem here is that the JSON is wrongly formatted. Here is the right format:
{
"name": "FF",
"good": {
"doors" : [
{
"name" : "Door Name 1",
"thumb": "http://placehold.it/134x134/ff0000/ffffff",
"specifics" : [
"Specifics 1a",
"Specifics 2a"
]
},
{
"name" : "Door Name 2",
"thumb": "http://placehold.it/134x134/b4da55/ffffff",
"specifics" : [
"Specifics 1b",
"Specifics 2b",
"Specifics 3b"
]
},
{
"name" : "Door Name 3",
"thumb": "http://placehold.it/134x134/0000ff/ffffff",
"specifics" : [
"Specifics 1c",
"Specifics 2c",
"Specifics 3c",
"Specifics 4c"
]
}
],
"walls" : [
{
"name" : "Chair Rail A",
"thumb": "http://placehold.it/134x134/0000ff/ffffff",
"specifics" : [
"Chair Rail A"
]
},
{
"name" : "Wall Paneling with Rosettes A",
"thumb": "http://placehold.it/134x134/b4da55/ffffff",
"specifics" : [
"Panel Moulding A",
"4\" Rossette"
]
},
{
"name" : "Wall Paneling with Rossettes B",
"thumb": "http://placehold.it/134x134/ff0000/ffffff",
"specifics" : [
"Panel Moulding A",
"6\" Rossette"
]
}
]
},
"best": {},
"better": {}
}
You used too many commas in your json.
I use jsoneditoronline.org to validate JSON and I find it very useful for the errors highlighting.
Upvotes: 0
Reputation: 22711
you have invalid json format, with lot of ,
in your code, validate your json code in online.
Online Validator Tool: http://jsonformatter.curiousconcept.com/
Upvotes: 0
Reputation: 63524
In a number of places in the JSON you have dangling commas. Get rid of those and your JSON will parse. I always find jsonlint.com to be a helpful tool in these occasions.
Upvotes: 1
Reputation: 94459
There is an extra comma after the array item, right here:
"specifics" : [
"Specifics 1b",
"Specifics 2b",
"Specifics 3b", //there is no next element, remove the ,
]
The same situation also occurs here:
"specifics" : [
"Chair Rail A",
]
There is also an extra comma after the walls property:
"walls" : [
{
"name" : "Chair Rail A",
"thumb": "http://placehold.it/134x134/0000ff/ffffff",
"specifics" : [
"Chair Rail A",
]
},
{
"name" : "Wall Paneling with Rosettes A",
"thumb": "http://placehold.it/134x134/b4da55/ffffff",
"specifics" : [
"Panel Moulding A",
"4\" Rossette"
]
},
{
"name" : "Wall Paneling with Rossettes B",
"thumb": "http://placehold.it/134x134/ff0000/ffffff",
"specifics" : [
"Panel Moulding A",
"6\" Rossette"
]
},
], //Remove me
Upvotes: 0