Product SiteDocumentation Site

Chapter 2. The JSON Syntax

2.1. JSON Strings
2.2. JSON Numbers
2.3. JSON Booleans
2.4. JSON Null
2.5. JSON Objects
The JSONiq query language was specifically designed for querying and processing JSON.
As stated on its home page http://www.json.org/, JSON is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.
JSON itself is only about syntax: a string may or may not match the JSON grammar. If it does, then it is well-formed JSON. The JSON syntax is made of the following building blocks: objects, arrays, strings, numbers, booleans and nulls. Let us begin with a quick overview of all these building blocks.

2.1. JSON Strings

Strings are double-quoted. To put it simply, they are sequences of Unicode characters with absolutely no restriction:
"foo",
"What NoSQL solutions are out there?"
However, syntactically, some of these characters must be escaped with backslashes (escape sequence). This includes double quotes, escaped as \" -- because otherwise they could be confused with the end of a string -- and backslahes themselves, escaped as \\ -- because otherwise you would not know if you mean a backslash character, or if you are escaping the following character.
"What \"NoSQL\" solutions are out there?"
Finally, all Unicode control characters (null, new line, form feed, delete...) are not allowed directly and must be built with an escape sequence. Any Unicode character, including control characters, can be built with \u followed by the four hexadecimal digits that identify it within Unicode. The most frequent control characters even have their own shortcuts: \n (new line), \t (tab), \r (carriage return), \b (backspace), \f (form feed). The slash can also be obtained with \/, although it is fine too if it appears alone. This is useful in JSON-hosting environments where slashes are special.
"What \"NoSQL\" solutions are out there:\n"
"MapReduce\u000AMongoDB\n\u0085"