Skip to content

Commit da4b6f2

Browse files
committed
tech review
1 parent 704e27c commit da4b6f2

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

source/data-formats/extended-json.txt

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ The following example outputs an Extended JSON string in the Relaxed format:
108108
.. input::
109109
:language: js
110110

111-
import { Binary, Code, BSON } from 'mongodb';
111+
import { Code, BSON } from 'mongodb';
112112
const EJSON = BSON.EJSON;
113113

114114
const doc = {
@@ -125,7 +125,7 @@ The following example outputs an Extended JSON string in the Relaxed format:
125125
:language: none
126126
:visible: false
127127

128-
[{"foo":[1,2]},{"bar":{"hello":"world"}},{"code":{"$code":"function x() { return 1; }","$scope":{}}},{"date":{"$date":"2024-07-20T14:30:00Z"}}]
128+
{"foo":[1,2],"bar":{"hello":"world"},"code":{"$code":"function x() { return 1; }","$scope":{}},"date":{"$date":"2024-07-20T14:30:00Z"}}
129129

130130
By default, the ``stringify()`` method returns the Extended JSON string in the
131131
Relaxed format. To specify the Canonical format, set the ``relaxed``
@@ -138,7 +138,8 @@ The following example shows how to output Extended JSON in the Canonical format:
138138
.. input::
139139
:language: js
140140

141-
const { Binary, Code, EJSON } = require('bson');
141+
import { Code, BSON } from 'mongodb';
142+
const EJSON = BSON.EJSON;
142143

143144
const doc = {
144145
foo: [1, 2],
@@ -154,7 +155,7 @@ The following example shows how to output Extended JSON in the Canonical format:
154155
:language: none
155156
:visible: false
156157

157-
[{"foo":[{"$numberInt":"1"},{"$numberInt":"2"}]},{"bar":{"hello":"world"}},{"code":{"$code":"function x() { return 1; }","$scope":{}}},{"date":{"$date":{"$numberLong":"1721485800000"}}}]
158+
{"foo":[{"$numberInt":"1"},{"$numberInt":"2"}],"bar":{"hello":"world"},"code":{"$code":"function x() { return 1; }","$scope":{}},"date":{"$date":{"$numberLong":"1721485800000"}}}
158159

159160
Read Extended JSON
160161
------------------
@@ -187,8 +188,7 @@ JavaScript value or object by using the ``parse()`` method:
187188
"$scope": {}
188189
},
189190
"bin": { "$binary": { "base64": "AQIDBA==", "subType": "00" } }
190-
}`;
191-
191+
}`;
192192

193193
const doc = EJSON.parse(ejsonStr);
194194
console.log(doc);
@@ -197,12 +197,12 @@ JavaScript value or object by using the ``parse()`` method:
197197
:language: none
198198
:visible: false
199199

200-
[
201-
{ foo: [ 1, 2 ] },
202-
{ bar: { hello: 'world' } },
203-
{ code: new Code('function x() { return 1; }', {}) },
204-
{ date: 2024-07-20T14:30:00.000Z }
205-
]
200+
{
201+
foo: [ 1, 2 ],
202+
bar: { hello: 'world' },
203+
code: new Code('function x() { return 1; }', {}),
204+
bin: Binary.createFromBase64('AQIDBA==', 0)
205+
}
206206

207207
.. note::
208208

0 commit comments

Comments
 (0)