I tried to parse a big JSON file using PHP and it always give me errors.
When I tried to validate the JSON file using http://jsonlint.com/ I encountered a lot of error in which there are some words separated by “unwanted” space and newline character like this:
{
"id": "1",
"qn
ame": "detik.co.id.",
"source": "undefined"
},
notice the word “qname” is separated into “qn” and “ame”. between those two there are space and newline characters.
the correct one should look like this:
{
"id": "1",
"qname": "detik.co.id.",
"source": "undefined"
},
since there are a lot of similar error it would be painful to remove those characters manually one by one. Is there any quicker way to deal with this problem?
Depending on the data, you could just get rid of all the space and newline characters:
But of course that will break if you have data with embedded spaces like: