wxJSON - The wxWidgets implementation of JSON
Here is an example of JSON formatted data:
"title" : "How to catch Peter Pan",
"author" : "Captain Hook",
"pages" : 285,
"price" : 29.95,
And this is the same data in XML format:
<book title="How to catch Peter Pan" author="Captain Hook" pages=285 price=29.95>
As you can see, JSON format is much more readable by humans and uses a syntax similar to many C-like languages. Someone may say that XML is object-oriented and JSON in not. The answer is that none of the two formats is really object-oriented. In fact, XML is a document-oriented format while JSON is a data-oriented format.
JSON handles data. There are the following data types in JSON:
- strings: a string is a sequence of ZERO or more unicode characters wrapped in double quotes, using backslash escapes
- numbers: a number is very much like a C or Java number, except that the octal and hexadecimal formats are not used
- the following three literals: null, true and false
- objects: a JSON object is a collection of name/value pairs
- arrays: an array is an ordered collection of values
JSON is built on two structures:
- the object: a collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
- the array: an ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
The JSON object is an unordered collection of key/value pairs (or name/value pairs). The keys are strings and the values are any of the JSON types including object and array. A colon separates the keys from the values, and comma separates the pairs. The whole thing is wrapped in curly braces. It maps directly onto objects, structs, records, and hashtables. This is an example of a JSON object:
"name": "Jack (\"Bee\") Nimble",
"frame rate": 24
The JSON array is an ordered collection of values separated by commas. The whole thing is wrapped in square brackets. It maps directly onto arrays, vectors, and lists. These are examples of JSON arrays:
["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
[0, -1, 0],
[1, 0, 0],
[0, 0, 1]
wxJSON compiles and works (at least, it should
work) on wxWidgets 2.8 (minimum is wxW 2.8.4) and wxWidgets 2.9 (minimum is 2.9.1).
The wxJSON library is a JSON implementation for wxWidgets and it is composed of only three classes which uses the wxBase
library: the only needed classes are: wxString
and the wxMBConv
-derived classes. wxJSON does not depend on the std::string
class nor on STL containers.
Starting from version 1.2 the wxJSON library compiles also if wxWdigets is configured with the
--enable-stl flag then STL is available for both wxWdigets and wxJSON. In fact, if STL is enabled, the wxJSON array type and key/value type are implemented using STL containers. Otherwise, the wxWidegts' own implementation of container classes is used. Note that from the point of view of the wxJSON user, the actual implementation is totally transparent: JSON values are accessed in the same way in both implementations. To know more read The array of values. and The map of key/value pairs..
The following three classes are defined in wxJSON:
- wxJSONValue this class holds the JSON value which can be an integer, a double, a boolean, a string, an array of JSON values or a map of key/value pairs
Pages related to this documentation:
library only consists of three source files and their related header files:
For info about installation of the library read the INSTALL text file in the top-level directory. You can download this library in the following ways:
- using anonymous access to the Subversion repository of the wxCode project on SourceForge. You will need the bakefile tools in order to generate the makefiles for your system / compiler to actually compile the library unless you write it yourself.
- download the tarball which contains the makefiles for the most common systems / compilers by clikking here
library is a complete implementation of the JSON data-interchange format. All JSON specifications are implemented in this library plus some extensions in the writer and in the parser class.
JSON data format is very stable. It is accredited to be stable forever or, at least, until programming languages will be based on numbers, strings, booleans, structures and arrays. This version (1.2) is a stable release but there are plans to add some new features to the library (see http://luccat.users.sourceforge.net/wxjson/newver_01.html). Also, new versions of this library will be realesed in order to keep wxJSON compatible with the new releases of wxWidgets.
Many thanks to Bryan Ashby, Robbie Groenewoudt, Alexander Stigsen, Andrejs Cainikovs, Piotr Likus, Kolya Kosenko and Catalin for their help, hints, feedback.