JSON Syntax Error?

In JSON I am getting syntax error but I don’t know why? can someone help in finding the syntax error in it

{
    'jokes':[
        {
            'text':'How many Pear you can eat when your stomach is empty.' + '\n'
            'Girl: 7 Pears.' + '\n'
            'No, you are wrong, you can eat only one.' + '\n'
            'Girl: How can you say that.' + '\n'
            'Because when you eat 2nd Pear, your stomach will not empty!'
        },
{
'other-text':'Hell, is everything is cool'
}
    ];
}

there must be a comma between object properties.

Additionally, JSON uses " not '.

what is Additionally, JSON uses " not '.?

And I have only one property for every object in an array. in the first one text and in the other other-text

see the JSON specification at http://json.org/

that Girl: was confusing me. but then you can’t have two separate strings without an operator inbetween (line break does not count as operator).

I am using + to connect them. is that is not enough? if not what I have to use?

but only on the same line.

I should fit it in one line?

That doesn’t matter. If there is no operator between two strings (whether they’re on the same line or not), then it’s a syntax error.

but i am using the operator ‘+’ right so why it is not working?

I count 9 strings (in the value) and only 4 +

OMG! I saw that
thank you.

In JSON the property names must be double-quotes and not single quotes

Additionally I’m pretty sure that JSON does not support operators to concat strings, a string value should be a single string.

The new lines will depend on your implementation

I think this is more or less what you’re going for:

{
    "jokes":[
        {
          "text":"How many Pear you can eat when your stomach is empty.\nGirl: 7 Pears.\nNo, you are wrong, you can eat only one\nGirl: How can you say that\nBecause when you eat 2nd Pear, your stomach will not empty!"
        },
        {
          "other-text":"Hell, is everything is cool"
        }
    ]
}

yeah this worked for me.
Thank you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.