Libdjson

From Makers Local 256
Revision as of 01:27, 22 January 2010 by Opticron (Talk | contribs)

Jump to: navigation, search

Creator:
Opticron
Status:
Early Implementation
Born On:
14:32, 8 January 2010 (CST)
Last Updated:
01:27, 22 January 2010 (CDT)

Overview

This is a basic JSON parser written in D. It currently supports building JSON structures in code and reading them from a piece of text, as well as outputting those structures to JSON text. It is available from my SVN server.

Examples

Traversing a node tree with known structure is now fairly simple. As seen, foreach is possible over JSON objects and JSON arrays without explicit casting, since it is now part of the interface. If you try to foreach over something that isn't a container, you get an exception.

foreach(obj;jstr.readJSON()["phoneNumbers"]) {
 writefln("Got " ~ obj["type"].toJSONString.get ~ " phone number:" ~ obj["number"].toJSONString.get);
}

ToDo

  • Build some kind of query system so that it is easier to pull data out of the JSON object.
    • XPath inspired?, may always have to return an array of nodes