0

I am trying to parse this JSON string:

var string = '{"DataSerialized":{"DocumentElement":{"NAME_LIST":"FIELD_1":"VALUE_1","FIELD_2":"VALUE2","FIELD_3":"VALUE_3"}}}}';

how a JSON object how this:

{
    "DataSerialized":{
        "DocumentElement":{
            "NAME_LIST":{
                "FIELD_1":"VALUE_1",
                "FIELD_2":"VALUE2",
                "FIELD_3":"VALUE_3"
            }
        }
    }
}

For that, I tried with jQuery.parseJSON(string) but the result is wrong:

SyntaxError: JSON.parse: expected ',' or '}' after property value in object at line 1 column 60 of the JSON data

I think that it's a problem with quotes, but I don't know what's wrong exactly

Thanks in advance

SOLUTION: { after NAME_LIST

var string = '{"DataSerialized":{"DocumentElement":{"NAME_LIST":{"FIELD_1":"VALUE_1","FIELD_2":"VALUE2","FIELD_3":"VALUE_3"}}}}';

2
  • 2
    JSON uses double not single quotes. jsonlint.com Commented Oct 20, 2014 at 14:38
  • 1
    your JSON is invalid, you have an extra closing curly brace. Commented Oct 20, 2014 at 14:39

4 Answers 4

4

You have one missing a { after NAME_LIST and you should use " not '

Sign up to request clarification or add additional context in comments.

2 Comments

Actually there is one missing { after NAME_LIST. Would still be invalid after your changes.
Yes, this was the problem, { after NAME_LIST. Thanks a lot
0

This string:

var string = "{'DataSerialized':{'DocumentElement':
    {'NAME_LIST':'FIELD_1':'VALUE_1','FIELD_2':'VALUE2','FIELD_3':'VALUE_3'}}}}";

Has one too many closing braces.

Comments

0

When you use $.parseJSON you should use " instead of '

if you have any problem with json format. Try jsonformatter

1 Comment

Even that it won't be valid, try to use Python json.load("hisjson") it won't work, Json uses double quotes !
0

You have a wrong JSON format, you miss one { after name list. There is correct example

var string = '{"DataSerialized":{"DocumentElement":{"NAME_LIST":{"FIELD_1":"VALUE_1","FIELD_2":"VALUE2","FIELD_3":"VALUE_3"}}}}';
JSON.parse(string);

Try to run it on browser dev console and then you will see correct object

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.