I have a JSON which is verified in the JSONlint, but I cannot use JSON.parse() as it is not working. What is the problem with the JSON here, if JSON.prase() cannot be used what are my alternatives.
JSON string : "{Products: [{Id: 1,Increment: 5,Max: 1000,Min: 25,allowed: false,Desc: product description,Name:Product Name,Qty: 0}]}"
To a JSON be valid, your object keys must be inside double quotes:
{ "validKey": 123 }
^ ^
| |
------------- These double-quotes are required!
JSONLint said that it's alright because you pasted the JSON as you pasted here, wrapped in quotes:
"{Products: [{Id: 1,Increment: 5,Max: 1000,Min: 25,allowed: false,Desc: product description,Name:Product Name,Qty: 0}]}"
And this is a json string with a JSON inside, not a JSON!
If you try to JSONLint without the Quotes you will get this error:
Error: Parse error on line 1:
{ Products: [{ Id: 1
--^
Expecting 'STRING', '}', got 'undefined'
Your strings and keys should be quoted. This is valid JSON that will be correctly parsed by JSON.parse()
{
"Products": [
{
"Id": 1,
"Increment": 5,
"Max": 1000,
"Min": 25,
"allowed": false,
"Desc": "product description",
"Name": "Product Name",
"Qty": 0
}
]
}
You can read more about the standard here: https://www.json.org/
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