wxJSON - The wxWidgets implementation of JSON

version 1.1

http://luccat.users.sourceforge.net/wxjson/

Introduction

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

Here is an example of JSON formatted data:

 {
   "book":
   {
     "title"  : "How to catch Peter Pan",
     "author" : "Captain Hook",
     "pages"  : 285,
     "price"  : 29.95,
     "translations" :
     [
       "german",
       "french",
       "spanish",
       "italian"
     ]
   }
 }

And this is the same data in XML format:

 <book title="How to catch Peter Pan" author="Captain Hook" pages=285 price=29.95>
   <translations>
     <item "german"/>
     <item "french"/>
     <item "spanish"/>
     <item "italian"/>
   </translations>
 </book>

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 data format

JSON handles data. There are the following data types in JSON:

JSON is built on two structures:

The JSON object

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", 
    "format": {
        "type":       "rect",
        "size" :
        { 
          "width":      1920, 
          "height":     1080, 
        },
        "interlace":  false, 
        "frame rate": 24
    }
}

The JSON array

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]
  ]

The JSON implementation for wxWidgets

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, wxObjArray, wxHashMap, wxInputStream, wxOutputStream, wxArrayString and the wxMBConv -derived classes. wxJSON does not depend on the std::string class nor on STL containers.

The following three classes are defined in wxJSON:

Pages related to this documentation:

Installation

The wxJSON library only consists of three source files and their related header files:

 jsonvalue.cpp
 jsonreader.cpp
 jsonwriter.cpp

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:

Usefull links:

Limitations

The wxJSON 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.

One of the most important features that is not present in this JSON implementation is iterators. Many other JSON implementations do provide iterators for the array and the object JSON types. I do not implement them because they need STL containers and I do not want the wxJSON library to depend on STL although there is a plan to let the user choose the container to be used: wxWidget's implementation or STL (see http://luccat.users.sourceforge.net/wxjson/newver_01.html#vers12).

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.1) 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.

Contributors

Many thanks to Bryan Ashby, Robbie Groenewoudt, Alexander Stigsen, Andrejs Cainikovs, Piotr Likus and Kolya Kosenko for their help, hints, feedback.

Generated on Fri Nov 13 22:52:29 2009 for wxJSON by  doxygen 1.5.5