Closed GoogleCodeExporter closed 9 years ago
Unnecessary commas aren't valid JSON. Gson supports them when you're
databinding because it's lenient by default. Here's what JsonReader says on it:
"Setting the parser to lenient causes it to ignore the following syntax errors:
... Unnecessary array separators. These are interpreted as if null was the omitted value."
http://google-gson.googlecode.com/svn/trunk/gson/docs/javadocs/com/google/gson/s
tream/JsonReader.html#setLenient(boolean)
Your best bet is to avoid the avoid unnecessary commas in your documents.
Usually machine-generated JSON won't have them.
Original comment by limpbizkit
on 12 Jan 2012 at 3:58
Could you kindly reconsider this?
When writing the json manually (what I do quite often as I use it for
configuration)
the trailing comma bites me quite often. Lenient mode doesn't help here at all
as the null leads to worse problems later.
Note that both Java and Javascript allow and IGNORE trailing commas in array
initializers, see
http://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.6
http://ecma262-5.com/ELS5_HTML.htm#Section_11.1.5
Maybe one day JSON will too as it's very practical.
In most browsers "[1,, 2,]" is the same as "[1, null, 2]", since the trailing
comma gets ignored and only the others get interpreted as nulls.
The needed change is very trivial (just drop the condition above the comment
`fall-through to handle ",]"`).
Original comment by Maaarti...@gmail.com
on 29 Jul 2012 at 8:58
Original issue reported on code.google.com by
martynas...@gmail.com
on 12 Jan 2012 at 2:10