JSON is a data-interchange format, which is easy to read and write and also easy to parse and generate by a machine. The JSON text format is a language format that is language independent but makes use of conventions familiar to commonly used languages such as Java, C, and JavaScript.
Essentially a JSON document is an object, a collection of name/value pairs enclosed in curly braces {}
. Each name in the collection is followed by ‘:
’ and each subsequent name/value pair is separated from the preceding by a ',
'. An example of a JSON document is as follows in which attributes of a catalog are specified as name/value pairs.
{
"journal":"Oracle Magazine",
"publisher":"Oracle Publishing",
"edition": "January February 2013"
}
The name in name/value pairs must be enclosed in double quotes "". The value must also be enclosed in "" if a string includes at least a single character. The value may have one of the types discussed in Table 1-2.
Table 1-2. JSON Data Types
Type | Description | Example |
string | A string literal. A string literal must be enclosed in "". |
The string may consist of any Unicode character except
The following JSON document is valid. |
number | A number may be positive or negative, integer or decimal. | |
array | An array is a list of values enclosed in | |
true false | The value may be a Boolean true or false. | |
null | The value may be null. | |
object | The value may be another JSON object. | { |
The JSON document model is most suitable for storing unstructured data, as the JSON objects can be added in a hierarchical structure creating complex JSON documents. For example, the following JSON document is a valid JSON document consisting of hierarchies of JSON objects.
{
"c1": "v1",
"c2": {
"c21":[1,2,3],
"c22":
{
"c221":"v221",
"c222":
{
"c2221":"v2221"
},
"c223":
{
"c2231":"v2231"
}
}
}
}