Difference between revisions of "Libdjson"
From Makers Local 256
(populate library page) |
(update docs a tad, traversing the tree is much easier, now) |
||
Line 7: | Line 7: | ||
==Overview== | ==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 [http://opticron.no-ip.org/svn/branches/libdjson my SVN server]. | 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 [http://opticron.no-ip.org/svn/branches/libdjson 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== | ==ToDo== | ||
* Build some kind of query system so that it is easier to pull data out of the JSON object. | * 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 | ** XPath inspired?, may always have to return an array of nodes | ||
− | |||
Revision as of 01:27, 22 January 2010
Creator: |
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