Skip to content

Commit 3b0d4da

Browse files
committed
add format info
1 parent f903bef commit 3b0d4da

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

source/data-formats/extended-json.txt

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,110 @@ set of keys prefixed with "``$``" to represent field type information that
2626
directly corresponds to each type in BSON, the format that MongoDB uses to
2727
store data.
2828

29+
Extended JSON Formats
30+
---------------------
31+
32+
MongoDB Extended JSON features different string formats to represent BSON data.
33+
Each of the different formats conform to the JSON RFC
34+
and meet specific use cases. The **extended** format, also known as the
35+
**canonical** format, features specific representations for every BSON type
36+
for bidirectional conversion without loss of information. The **Relaxed mode**
37+
format is more concise and closer to ordinary JSON, but does not represent
38+
all the type information such as the specific byte size of number fields.
39+
40+
See the following table to see a description of each format:
41+
42+
.. list-table::
43+
:header-rows: 1
44+
:stub-columns: 1
45+
:widths: 10 40
46+
47+
* - Name
48+
- Description
49+
50+
* - **Extended**
51+
- | Also known as the *canonical* format, this JSON representation avoids loss of BSON type information.
52+
| This format prioritizes type preservation at the loss of human-readability and interoperability with older formats.
53+
54+
* - **Relaxed Mode**
55+
- | JSON representation that describes BSON documents with some type information loss.
56+
| This format prioritizes human-readability and interoperability at the loss of certain type information.
57+
58+
* - **Shell**
59+
- | JSON representation that matches the syntax used in the MongoDB shell.
60+
| This format prioritizes compatibility with the MongoDB shell which often uses JavaScript functions to represent types.
61+
62+
* - **Strict**
63+
- | *Deprecated.* This representation is the legacy format that fully conforms to the `JSON RFC <http://www.json.org/>`__ which allows any JSON parser to read the type information.
64+
| The legacy API uses this format.
65+
66+
.. _extended_json_example_section:
67+
68+
.. note::
69+
70+
The driver parses the ``$uuid`` Extended JSON type from a string to a
71+
``BsonBinary`` object of binary subtype 4. For more information about ``$uuid`` field
72+
parsing, see the
73+
:spec:`special rules for parsing $uuid fields </extended-json.rst#special-rules-for-parsing-uuid-fields>`
74+
section in the extended JSON specification.
75+
2976
To learn more about JSON, BSON, and Extended JSON, see
3077
`our article about JSON and BSON <https://www.mongodb.com/resources/basics/json-and-bson>`__
3178
and :manual:`Extended JSON </reference/mongodb-extended-json/>` in the {+mdb-server+} manual.
3279

80+
Extended JSON Examples
81+
~~~~~~~~~~~~~~~~~~~~~~
82+
83+
The following examples show a document containing an ObjectId, date, and long
84+
number field represented in each Extended JSON format. Click the tab that
85+
corresponds to the format of the example you want to see:
86+
87+
.. tabs::
88+
89+
.. tab:: Extended
90+
:tabid: extended-format
91+
92+
.. code-block:: json
93+
94+
{
95+
"_id": { "$oid": "573a1391f29313caabcd9637" },
96+
"createdAt": { "$date": { "$numberLong": "1601499609" }},
97+
"numViews": { "$numberLong": "36520312" }
98+
}
99+
100+
.. tab:: Relaxed Mode
101+
:tabid: relaxed-mode-format
102+
103+
.. code-block:: json
104+
105+
{
106+
"_id": { "$oid": "573a1391f29313caabcd9637" },
107+
"createdAt": { "$date": "2020-09-30T18:22:51.648Z" },
108+
"numViews": 36520312
109+
}
110+
111+
.. tab:: Shell
112+
:tabid: shell-format
113+
114+
.. code-block:: json
115+
116+
{
117+
"_id": ObjectId("573a1391f29313caabcd9637"),
118+
"createdAt": ISODate("2020-09-30T18:22:51.648Z"),
119+
"numViews": NumberLong("36520312")
120+
}
121+
122+
.. tab:: Strict
123+
:tabid: strict-format
124+
125+
.. code-block:: json
126+
127+
{
128+
"_id": { "$oid": "573a1391f29313caabcd9637" },
129+
"createdAt": { "$date": 1601499609 },
130+
"numViews": { "$numberLong": "36520312" }
131+
}
132+
33133
Read Extended JSON
34134
------------------
35135

0 commit comments

Comments
 (0)