JSON is designed to be lightweight and supports only four primitive data types:
- Numbers: This is a double-precision float
- String: Unicode text surrounded by double quotes
- True/false: Boolean values; they must be written in lowercase
- Null: This represents a null value
As you can see, there is no date data type. Dates are represented and processed as strings. A JSON string is a sequence of Unicode code points wrapped with quotation marks. All characters may be placed within the quotation marks, except for the characters that must be escaped. The following table provides the list of characters that must be escaped according to this specification and their JSON conform representation:
JSON escaping rules
Special character |
JSON conform character |
Double quote |
" |
Solidus |
/ |
Reverse solidus |
\ |
Backspace |
|
Form feed |
f |
New line |
|
Carriage return |
|
Tabulation |
|
In addition to this, all control characters with character codes in the range 0-31 need to be escaped too. In JSON output, they are represented in the following format: u<code>. Thus, the control character CHAR(0) is escaped as u0000, while CHAR(31) is represented by u001f.
The structure of a JSON string is shown in the following figure: