Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON.parse: expected property name or '}'

Tags:

json

parsing

Data contains (/"/):

 {"test":"101","mr":"103","bishop":"102"} 

script:

console.log($.parseJSON(result)); 

I'm getting error,

JSON.parse: expected property name or '}'. 
like image 299
realnumber Avatar asked Nov 04 '11 17:11

realnumber


People also ask

What is Property name in JSON?

Objects are the mapping type in JSON. They map “keys” to “values”. In JSON, the “keys” must always be strings. Each of these pairs is conventionally referred to as a “property”.

How do I fix unexpected token in JSON error?

The "Unexpected token u in JSON at position 0" error occurs when we pass an undefined value to the JSON. parse or $. parseJSON methods. To solve the error, inspect the value you're trying to parse and make sure it's a valid JSON string before parsing it.


1 Answers

Had same issue when used single quotes in JSON file, changed to double quotes for all string properties/values and it's working OK now, hope it helps anyone....

Change:

JSON.parse("{'wrongQuotes': 5}")  

To:

JSON.parse('{"rightQuotes": 5}') 
like image 128
alchemication Avatar answered Oct 19 '22 23:10

alchemication