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” } ] } ]
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.
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.
Exceptions. Throws a SyntaxError exception if the string to parse is not valid 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.
JSON string literals must use normal quote characters ("
), not smart quotes (“”
).
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" } ] } ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With