27

I am working on a restful api and have been validating with http://jsonlint.com/. After combining two JSON objects I ran into;

Parse error on line 932:
...ssions": 329    }],[    {        "m
---------------------^
Expecting 'EOF'

I looked around and found this question but all of the answers point to not having a comma, where in my problem I do have a comma. What else could the validator be looking for?

it is pointing at the code between my object arrays;

],
[
2
  • Please show a complete representative example of the JSON in question. I've taken an educated guess at what the problem is, but a complete, minimal example is always the better way to go. Mar 3, 2014 at 16:24
  • JSON is a text representation of data structure. The only valid JSON processing is to parse it to get a data structure equivalent to the one used to generate the JSON. Concatenating JSONs, with or without a separator, does not produce a JSON.
    – axiac
    Jan 25 at 12:41

4 Answers 4

45

You haven't shown enough of your JSON, but I'm guessing it looks like this:

[
    {"some": "object"},
    {"some": "object"}
],
[
    {"some": "object"},
    {"some": "object"}
]

...which is invalid. In JSON, there must be one top-level item (which in a complete JSON document must either an object or an array).

If you're combining two responses, you might make each of them the value of a property on a wrapper object, e.g.:

{
    "response1": [
        {"some": "object"},
        {"some": "object"}
    ],
    "response2": [
        {"some": "object"},
        {"some": "object"}
    ]
}
2
  • Your guess was correct, the first block is the way I put my JSON together. I will try to figure out your solution. Thanks.
    – Jordan.J.D
    Mar 3, 2014 at 18:50
  • @Jordan.J.D Did you happen PHP and share a algorithm for this transformation?
    – staminna
    Dec 2, 2020 at 11:19
2

In my case, it was a semi-colon at the end of JSON object that was throwing this error on jsonlint:

Expecting 'EOF', '}', ',', ']', got 'undefined'

Removing that solved it.

0

I am no expert on multi root JSON structures But here is what I did.. Just changed the encoding of the stream to UTF-8 and my PHP code started working very well

0

remove doubles quotes from brackets [

1
  • 1
    Welcome to StackOverflow. Could you provide more context to your answer and clarify for example which double quotes you mean? In the given example no double quotes are surrounding the brackets.
    – NOhs
    Feb 27, 2020 at 12:42

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.