CopperSpice API  1.9.1
JSON Support

Classes for reading and writing JSON syntax. More...

Classes

class  QJsonArray
 Encapsulates a JSON array More...
 
class  QJsonDocument
 Provides a way to read and write JSON documents More...
 
class  QJsonObject
 Encapsulates a JSON object More...
 
class  QJsonParseError
 Used to report errors during JSON parsing More...
 
class  QJsonValue
 Encapsulates a value in JSON More...
 

Detailed Description

JSON, an acronym for JavaScript Object Notation, is a format which uses human readable text as a way to transmit or store data objects which consist of key / value pairs. It is a very common format and widely used as a data exchange format on the Internet. JSON is considered to be a replacement for XML in many systems. The official Internet media type for JSON is application/json.

The JSON support in CopperSpice provides a simple API which is used to parse, modify, and save JSON data.

For additional details about the design of the JSON data format refer to this the JSON WebSite and RFC-4627.

Overview

The JSON format provides a limited number of supported data types. A value can be one of the data types shown below.

A boolean value is represented by the key word true or false. JSON does not explicitly specify the valid range for numbers and support is limited to the validity range and precision of doubles. A string can be any valid UTF-8 Unicode string.

An array is a list of values in square brackets and separated by a comma.

An object is a collection of key/value pairs. All of the keys in an object must be a string. An object can not contain any duplicate keys. JSON objects are enclosed in curly brackets and separated by a comma.

The separator between keys and values in an object is a colon.

The following is a sample JSON document encoding a person, their age, address, and phone numbers. The JSON object has with 5 key/value pairs. Two of the values are strings, the third value is a number, which is then followed by another object containing an array.

{
"FirstName": "John",
"LastName": "Doe",
"Age": 43,
"Address": {
"Street": "Downing Street 10",
"City": "London",
"Country": "Great Britain"
},
"Phone numbers": [
"+44 1234567",
"+44 2345678"
]
}

JSON Document

A valid JSON document consists of either a JSON array or a JSON object, so a document always starts with a square or curly bracket.