Trailing commas in JSON

142 views
Skip to first unread message

Anthony Martin

unread,
Nov 2, 2010, 3:57:14 AM11/2/10
to golan...@googlegroups.com
Some buggy programs (*cough* Firefox *cough*)
output trailing commas after the last element
in an object or array. This is in violation
of the JSON spec.

I'm sending this to the list to save others
from wasting their time as I so unfortunately
did.

Anthony


diff -r a0353a269983 src/pkg/json/scanner.go
--- a/src/pkg/json/scanner.go Mon Nov 01 17:49:06 2010 -0700
+++ b/src/pkg/json/scanner.go Tue Nov 02 00:11:18 2010 -0700
@@ -284,7 +284,7 @@
case parseObjectValue:
if c == ',' {
s.parseState[n-1] = parseObjectKey
- s.step = stateBeginString
+ s.step = stateBeginStringOrEmpty
return scanObjectValue
}
if c == '}' {
@@ -294,7 +294,7 @@
return s.error(c, "after object key:value pair")
case parseArrayValue:
if c == ',' {
- s.step = stateBeginValue
+ s.step = stateBeginValueOrEmpty
return scanArrayValue
}
if c == ']' {

Jessta

unread,
Nov 2, 2010, 7:31:41 AM11/2/10
to Anthony Martin, golan...@googlegroups.com
On Tue, Nov 2, 2010 at 6:57 PM, Anthony Martin <al...@pbrane.org> wrote:
> Some buggy programs (*cough* Firefox *cough*)
> output trailing commas after the last element
> in an object or array. This is in violation
> of the JSON spec.
>
> I'm sending this to the list to save others
> from wasting their time as I so unfortunately
> did.

Have you filed a bug report with firefox?
It seems better to fix the buggy firefox than to make Go buggy too.

--
=====================
http://jessta.id.au

Jessta

unread,
Nov 2, 2010, 7:37:58 AM11/2/10
to Anthony Martin, golan...@googlegroups.com

Ah, looks like they'll fix it in the next version,
http://whereswalden.com/2010/09/08/spidermonkey-json-change-trailing-commas-no-longer-accepted/

--
=====================
http://jessta.id.au

Anthony Martin

unread,
Nov 2, 2010, 4:15:20 PM11/2/10
to Jessta, golan...@googlegroups.com
Jessta <jes...@jessta.id.au> once said:
> It seems better to fix the buggy firefox than
> to make Go buggy too.

I thought by posting to golang-nuts instead of
golang-dev there would be no confusion. Well, I
guess not. To be clear, I do not propose adding
this to the json package.

Anthony

Reply all
Reply to author
Forward
0 new messages