yitzih
yitzih

Reputation: 3118

JSON Parse Error: Expecting 'STRING'

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” } ]
    }
]   

Upvotes: 35

Views: 118100

Answers (5)

Ahmedakhtar11
Ahmedakhtar11

Reputation: 1458

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

Upvotes: -2

ilgice
ilgice

Reputation: 41

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

Upvotes: 0

Ajit Dhdharia
Ajit Dhdharia

Reputation: 43

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.

Upvotes: 0

11thdimension
11thdimension

Reputation: 10633

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" } ]
    }
]

Upvotes: 7

SLaks
SLaks

Reputation: 887405

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

Upvotes: 64

Related Questions