Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONParser.parse() throws a parse exception on trailing and leading whitespace of a JSON String. #101

Open
GoogleCodeExporter opened this issue Dec 24, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Have a valid JSON string with trailing whitespace after the last '}'.
2. Parse it with JSONParser.parse or JSONValue.parse


Expected: If the JSON is valid it should be parsed as an object.
Seen: An NullPointerException or a ParseException is thrown with the message: 
Unexpected character () at (index after last '}' ). 


JSON simple 1.1 on Java 1.6

Calling trim() on the json string before parsing won't throw the error. 

This scenario happened when I was parsing JSON messages sent through UDP as 
bytes and received in a fixed size byte[] buffer. Not realising that there are 
whitespaces in front of the json string (The error is non descriptive, doesn't 
show the character on which the parse error occurred is a space). 

Should the parser call trim() implicitely?


Original issue reported on code.google.com by [email protected] on 16 Sep 2014 at 6:18

@GoogleCodeExporter
Copy link
Author

Original comment by [email protected] on 16 Sep 2014 at 7:16

  • Changed state: Accepted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant