Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is JSON invalid when commas in string?

Tags:

java

json

jackson

Anyone know why this JSON is invalid?

{"street_address":"Stone House Lane, Peckforton
, Tarporley
, London, Cheshire"}

I'm using Jackson for Java and it's complaining about

java.lang.IllegalArgumentException: com.fasterxml.jackson.core.JsonParseException:     Unexpected end-of-input: was expecting closing quote for a string value
at [Source: java.io.StringReader@6ad16fc1; line: 1, column: 405]

I noticed this JSON is considered invalid on this online site as well: http://jsonviewer.stack.hu/

Answer: Thanks, for those who are curious I've removed these unreadable characters using tr -cd '\11\12\15\40-\176' < file > cleanFile

like image 339
Popcorn Avatar asked Jun 18 '14 22:06

Popcorn


1 Answers

After copying/pasting your exact text, it shows as an invalid JSON variable. Then, I just copied/pasted the same content into a notepad (using Windows 7) and noted there are strange characters in your string (these characters cannot be seen in this page nor in web editors, so I'm using a blank space instead):

{"street_address":"Stone House Lane, Peckforton
 , Tarporley
 , London, Cheshire"}
                                               ^           ^
                                               here and here

I just removed them and worked as expected. Copy/paste it from here:

{"street_address":"Stone House Lane, Peckforton, Tarporley, London, Cheshire"}

After a more in-depth evaluation, the hexadecimal representation of this char is \u80A8.

like image 87
Luiggi Mendoza Avatar answered Sep 23 '22 13:09

Luiggi Mendoza