Updates to JSON parser and serializer

A bunch of bug reports followed by fixes and a major conceptual problem in the naming of the entry-points.

Most of the reports came in two comments on the scripting.com post.

The first, from Andrew Tunnell Jones, resulted in a new example that tests the two problems he caught.

1. We weren’t catching the “null” constant. This is encoded in Frontier as the built-in value nil. The serializer needed to watch for it, and it wasn’t.

2. The second is much more problematic. He included an empty list. This caught a problem in the way we view lists. Say you have a list named concepts with three values: 1, 15 and true. We create three items named concepts in the table, with each of the respective values. This works great until you give me an empty list. We create 0 items. Oops, we didn’t leave anything behind to serialize. So now we do. If there’s an empty list in the JSON text, we create an empty Frontier list. When you’re processing this, you should do nothing with it.

Peter Miller caught two problems..

3. A list with one element, a number, returns as a list with a string. This is actually a more general problem. It was always returning strings. A boolean true would return as the string “true” for example. I simply wrote the missing code.

4. The value “foo” returns as true. This is because the code expected either a list or a struct. A scalar value completely screwed things up. My design was wrong, we’re not just passing around tables that are either lists or structs, we have to be able to use JSON to represent single scalar values like “foo” and -198.02 and false. So I made the changes, which were easy, but there’s now a serious conceptual problem — the names of the routines: xml.jsonToTable and xml.tableToJson. That’s not what’s going on any longer. Better names would be json.compile and json.decompile. It’s still early enough in the process to make this change, I believe.

To get the fixes, choose Update opml.root from the File menu in the OPML Editor.

Update: Jim Roepcke discovered that xml.jsonToTable wasn’t properly handling strings containing a backslashed double-quote. Here’s a simple example. The problem has been fixed.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: