Why is this JSON invalid?

1.1k Views Asked by At
{
    "already_public": "null",
    "status": "true",
    "message": "Service provider added successfully",
    "detail": {
        "id": "1175",
        "address_1": "",
        "address_2": "",
        "profession": "Accountant",
        "city": "",
        "company": "",
        "email_1": "",
        "email_2": "",
        "firstname": "das\' feet",
        "lastname": "",
        "life_block": "Family",
        "work_phone": "",
        "mobile_phone": "",
        "home_phone": "",
        "fax": "",
        "state": "",
        "title": "",
        "website": "",
        "zip": "",
        "ismyprovider": "1",
        "privacy": "null",
        "img_url": "http://localhost/mtube/uploads/blank_pic.png"
    },
    "inresponseto": "addServiceProvider"
}

Everything is ok except for this line

"firstname": "das\' feet"

It has a single quote within double quote. Despite having a \ before the character this json is being invalidated by jsonlint.

3

There are 3 best solutions below

3
On BEST ANSWER

there should be double slash to escape slash char

"firstname": "das\\' feet"
0
On

The single quote ' shouldn't be escaped:

enter image description here

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

JSON.org

As you can see, the single quote shouldn't be escaped.

Or if you want to keep the \, than you need to escape that:

 "firstname": "das\\' feet",
0
On

You do not need to escape single quote. More info is here