JSON parser for the OPML Editor

We now have a full-blown JSON parser running in the OPML Editor.

It’s written as a script, runs pretty fast.

It works exactly as xml.compile does. It takes two parameters, a string of JSON text and the address of a table. The table returns in the same format as xml.compile produces, so all the techniques we’ve developed for walking XML structures work equally well for JSON structures. They are the same.

There is also a serializer that works exactly as xml.decompile does.

The two routines are:

xml.jsonToTable (s, adrtable)

xml.tableToJson (adrtable) returns string

There is an important difference — XML has attributes and JSON does not. This came up when producing a JSON serialization of an RSS structure. Following other people’s examples, when I see an element that has attributes, I include the attributes as sub-items and create a sub-element called #value, which contains the element’s value. There is an optional parameter on xml.jsonToTable that says whether or not it should watch for these, and automatically collapse them.

The code for the parser has been released. If you update opml.root you’ll get it. You can read the source here. And if you have some valid JSON around, you can test the parser using this web app that I put together to help me test it.

http://json.scripting.com/

Bottom-line: Now I can build web apps that work with JSON.

One response to this post.

  1. […] ganz kurz, damit ich es nicht vergesse: Es gibt jetzt auch einen JSON-Parser für den OPML Editor. Für die, die Seltsames damit vorhaben. Ich hätte Lust, dazuzugehören. […]

    Reply

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: