Back in September localhostr updated its API to use JSON which meant my localhostr uploadr needed a JSON library to parse the responses from localhostr. Due to the way the update was done by localhostr, I didn't have much time to update localhostr uploadr and so I had a choice to make - either use an existing library or quickly implement one myself.
Having found JSON.org, I checked out the C++ JSON libraries and found most of them to be either part of a larger library (and so would add unnecessary code) or were overly complicated to interface with. Based on that, I decided I would write my own library that had 2 simple goals:
As localhostr's updated API would only be making use of a small set of the JSON specification (only the "string" and "bool" types), I only coded the parser to deal with those types when I added it to localhostr uploadr. Since then I have finished off the parser to include all types and it is now at a stage whereby it can be released under the GPLv2 license. The library complies with the ECMA JSON specification with a single notable exception which is the library allows tab characters to exist in JSON strings due to it being used by sites such as GMail.
The above exception only applies to the parser (or decoder) in the library and any JSON text that is outputted by the library conforms completely to the specification.
The library consists of 2 classes, JSON and JSONValue, which are attached at the bottom of this post (both cpp and header files) as well as a link to a basic documentation page. The JSON class acts similar to the Javascript JSON object and contains Parse() and Stringify() methods for dealing with decoding and encoding JSON text. The JSONValue class is the class that deals with representing the various JSON values in a C++ way.
Along with the 4 source files, I have attached a ZIP file that contains the library and a demo project to show how to use the library. If you are on Windows you will need Visual Studio 2008 (or the Express edition of Visual C++) to compile and run the demo project, Linux users should just need the standard building tools. The demo project allows you to:
The library requires no 3rd party libraries and so can be dropped into any existing project effortlessly. It has been tested on Linux and Windows (using VS2008), if you come across any issues with using it on any system, feel free to contact me.