35

I am using JSONLint to parse some JSON and i keep getting the error:

Error: Parse error on line 1: [{“ product”: [{“
---^ Expecting 'STRING', '}', got 'undefined'

This is the code:

[
    {
        “product” :  [ { “code” : “Abc123”, “description” : “Saw blade”, “price” : 34.95 } ],
        “vendor” : [ { “name” : “Acme Hardware”, “state” : “New Jersey” } ]
    },

    {
        “product” :  [ { “code” : “Def456”, “description” : “Hammer”, “price” : 22.51 } ],
    },

    {
        “product” :  [ { “code” : “Ghi789”, “description” : “Wrench”, “price” : 12.15 } ],
        “vendor” : [ { “name” : “Acme Hardware”, “state” : “New Jersey” } ]
    },

    {
        “product” :  [ { “code” : “Jkl012”, “description” : “Pliers”, “price” : 14.54 } ],
        “vendor” : [ { “name” : “Norwegian Tool Suppliers”, “state” : “Kentucky” } ]
    }
]   
3
  • 6
    Don't use smart quotes. Commented Dec 31, 2015 at 20:13
  • What is smart quotes? Commented Dec 31, 2015 at 20:15
  • Oh ok looked it up and replaced all of them and it worked thanks! Commented Dec 31, 2015 at 20:18

5 Answers 5

64

JSON string literals must use normal quote characters ("), not smart quotes (“”).

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

2 Comments

It's also worth noting that the JSON is still invalid even after converting to normal quote characters. There is a trailing comma after “price” : 22.51 } ],. There is no item that follows it, so the comma should be removed.
I've just made this mistake using single quotes so don't use those either :)
8

You're using some unicode double quotes characters. Replace them with the normal " double quotes.

You also had some extra comma at the end in the second element.

Now it's alright

[
    {
        "product" :  [ { "code" : "Abc123", "description" : "Saw blade", "price" : 34.95 } ],
        "vendor" : [ { "name" : "Acme Hardware", "state" : "New Jersey" } ]
    },

    {
        "product" :  [ { "code" : "Def456", "description" : "Hammer", "price" : 22.51 } ]
    },
    {
        "product" :  [ { "code" : "Ghi789", "description" : "Wrench", "price" : 12.15 } ],
        "vendor" : [ { "name" : "Acme Hardware", "state" : "New Jersey" } ]
    },
    {
        "product" : [ { "code" : "Jkl012", "description" : "Pliers", "price" : 14.54 } ],
        "vendor" : [ { "name" : "Norwegian Tool Suppliers", "state" : "Kentucky" } ]
    }
]

Comments

0

JSON must use normal quote characters("), not smart quotes for(“”) for string literals.

To get the normal quote in JSON data format: right-click on browser window and select - view page source.

Comments

0

This is how I save the MySQL text format and get the json_decode data

[{"5":[29,30,5],"6":[1,2,3],"7":[4,5,6]}]

$row_days= $rows['days'];

var_dump(json_decode($row_days, true));

Result array (size=1)

0 => array (size=3) 5 => array (size=3) 0 => int 29 1 => int 30 2 => int 5 6 => array (size=3) 0 => int 1 1 => int 2 2 => int 3 7 => array (size=3) 0 => int 4 1 => int 5 2 => int 6

Comments

-2

For me it was because I was doing the following in an older JavaScript framework. But might not be the case with modern JS frameworks.

object.age = 31 

instead of the better recognized way:

object["age"] = 31

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.