Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON Parse Error: Expecting 'STRING'

Tags:

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” } ]     } ]    
like image 878
yitzih Avatar asked Dec 31 '15 20:12

yitzih


People also ask

Why does JSON parse not work?

parse() itself cannot execute functions or perform calculations. JSON objects can only hold simple data types and not executable code. If you force code into a JSON object with a string, you must use the Javascript eval() function to convert it into something the Javascript interpreter understands.

What is a parse error in JSON?

parse: unexpected character" error occurs when passing a value that is not a valid JSON string to the JSON. parse method, e.g. a native JavaScript object. To solve the error, make sure to only pass valid JSON strings to the JSON.

What error does JSON parse () throw when the string to parse is not valid JSON?

Exceptions. Throws a SyntaxError exception if the string to parse is not valid JSON.

How do I correct JSON?

The best way to find and correct errors while simultaneously saving time is to use an online tool such as JSONLint. JSONLint will check the validity of your JSON code, detect and point out line numbers of the code containing errors.


2 Answers

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

like image 64
SLaks Avatar answered Sep 18 '22 14:09

SLaks


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" } ]     } ] 
like image 21
11thdimension Avatar answered Sep 20 '22 14:09

11thdimension