This is the json .
"{
'places': [
{
'name': 'New\x20Orleans,
\x20US\x20\x28New\x20Lakefront\x20\x2D\x20NEW\x29',
'code': 'NEW'
}
]
}"
I am getting json parsererror. I am checking on http://jsonlint.com/ and it shows following error
Parse error on line 1:
"{ 'places': [
^
Expecting '{', '['
Please explain what are the problems with the json and do I correct it?
If you literally mean that the string, as a whole, is your JSON text (containing something that isn't JSON), there are three issues:
It's just a JSON fragment, not a full JSON document.
Literal line breaks within strings are not valid in JSON, use
\n
.\x
is an invalid escape sequence in JSON strings. If you want your contained non-JSON text to have a\x
escape (e.g., when you read the value of the overall string and parse it), you have to escape that backslash:\\x
.In a full JSON document, the top level must be an object or array:
Most JSON parsers support parsing fragments, such as standalone strings. (For instance, JavaScript's
JSON.parse
supports this.) http://jsonlint.com is doing full document parsing, however.Here's your fragment wrapped in an object with the line breaks and
\x
issue handled:The text within the string is also not valid JSON, but perhaps it's not meant to be. For completeness: JSON requires that all keys and strings be in double quotes (
"
), not single quotes ('
). It also doesn't allow literal line breaks within string literals (use\n
instead), and doesn't support\x
escapes. See http://json.org for details.Here's a version as valid JSON with the
\x
converted to the correct JSON\u
escape:...also those escapes are all actually defining perfectly normal characters, so: