frazman
frazman

Reputation: 33243

Where is the error in the following json

I have a json in following format( Its pretty long:( Please feel free to edit it in order to copy it.

http://jsfiddle.net/kZpBu/

and when i paste it here http://www.jsoneditoronline.org/ to visualize it.. it throws an error

I am trying to convert to this format http://jsfiddle.net/uNqe6/

which is very heirachical in nature whereas my jsons are bit flat..

It says that it was expecting an EOF instead of "," How is first format different than second? Thanks

Ahh.. they dont let me post without a code snippet

{"name": "topic 0", "children": [{"name": "river", "size": 260462}, {"name": "water", "size": 154470}, {"name": "lake", "size": 137116}, {"name": "mountain", "size": 87756}..

Upvotes: 0

Views: 54

Answers (4)

James Montagne
James Montagne

Reputation: 78650

http://jsonlint.com is a great site for things like this.

The error is in the fact that your JSON is in the following format:

{
  // stuff
} , {
  // stuff
}

objects separated by commas are not valid json. I suspect you want this to be an array, in which case you need to surround it in []:

[{
  // stuff
} , {
  // stuff
}]

Upvotes: 4

Paul Armstrong
Paul Armstrong

Reputation: 7156

Use http://jsonlint.com. It'll show you exactly where your error is.

Parse error on line 205:
...48        }    ]},{    "name": "top
--------------------^
Expecting 'EOF'

Upvotes: 2

DocMax
DocMax

Reputation: 12164

Your JSON is defining two objects like:

{"name":"topic 0" /*array*/},{"name":"topic 1" /*array*/}

which is a problem for the parser that is expecting an object. If you mean an array for the two, wrap the JSON in [] as:

[{"name":"topic 0" /*array*/},{"name":"topic 1" /*array*/}]

and http://www.jsoneditoronline.org/ is happy.

Upvotes: 3

Dave Newton
Dave Newton

Reputation: 160191

Between the two JSON objects that aren't in an array.

{
    "name": "topic 0",
    "children": [
        {
            "name": "river",
            "size": 260462
        },
// Lots of stuff deleted
        {
            "name": "great",
            "size": 24348
        }
    ]

}, // Right here.

{
    "name": "topic 1",
    "children": [
        {
            "name": "number",
            "size": 59354
        },
// Elided

Upvotes: 1

Related Questions