Click here to show or hide the menubar.

Home >  Archive >  2010 >  December >  18

Previous / Next

Question for JSON gurus
By Dave Winer on Saturday, December 18, 2010 at 9:25 AM.

A picture named lysol.gifAs you may recall, I wrote a JSON compiler and decompiler in October. After running a bunch of tests against other people's JSON, I was satisfied that it worked, and moved on. I mostly focused on the compiler, because that's usually the hard part, trying to understand all the variables that people can throw at you. JSON was, as advertised, pretty easy to work with (though not as easy, imho, as it could have been). No matter. permalink

Now we've got a format that's starting to gain traction, a JSONification of stream of news displayed by River2. A bunch of Javascript devs are working on renderings of this data, some of which are now already nicer than the one I use, but none are yet functional enough for me to switch to. permalink

But there's a problem with the JSON. permalink

Each group of news bits is organized as a bunch of scalar data, like feed name, url, when the feed was last read, etc. Then there are one or more news items. If there's one item I just include a struct named item. If there's more than one I include a list of structs. The list is named item. I understood this is the convention for repeating elements in JSON.  permalink

XML deals with it differently, they just allow more than one item with the same name. This causes other, different, headaches. permalink  permalink

In the screen shot above, there are two "updatedFeed" elements. The first has only one item, the second has more than one.  permalink

This causes problems for people in some languages because (apparently) it's hard for them to deal with an object without, in advance, knowing its type. So they say the solution is simple, always make it a list. Simple for them, but... :-) permalink

But this is not so simple on my end. Because I'm using a generic JSON serializer, and it would have no way of knowing that "item" should always be a list. Unless... permalink

One way of dealing with this (that I don't like and won't do) is to make everything a list. permalink

I was just wondering what other JSON-producing environments do in situations like this. permalink

PS: I have a workaround I can do fairly quickly that side-steps the problem, so it won't ultimately be a deal-stopper. But I'd like to solve the problem entirely in the serializer if possible, so the solution can be work in other cases. permalink

RSS feed for Scripting News
This site contributes to the community river.

© Copyright 1997-2012 Dave Winer. Last update: Saturday, December 18, 2010 at 9:53 AM Eastern. Last build: 8/26/2012; 6:03:31 PM. "It's even worse than it appears."

RSS feed for Scripting News

Previous / Next