@@ -108,7 +108,7 @@ The following example outputs an Extended JSON string in the Relaxed format:
108
108
.. input::
109
109
:language: js
110
110
111
- import { Binary, Code, BSON } from 'mongodb';
111
+ import { Code, BSON } from 'mongodb';
112
112
const EJSON = BSON.EJSON;
113
113
114
114
const doc = {
@@ -125,7 +125,7 @@ The following example outputs an Extended JSON string in the Relaxed format:
125
125
:language: none
126
126
:visible: false
127
127
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"}}
129
129
130
130
By default, the ``stringify()`` method returns the Extended JSON string in the
131
131
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:
138
138
.. input::
139
139
:language: js
140
140
141
- const { Binary, Code, EJSON } = require('bson');
141
+ import { Code, BSON } from 'mongodb';
142
+ const EJSON = BSON.EJSON;
142
143
143
144
const doc = {
144
145
foo: [1, 2],
@@ -154,7 +155,7 @@ The following example shows how to output Extended JSON in the Canonical format:
154
155
:language: none
155
156
:visible: false
156
157
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"}}}
158
159
159
160
Read Extended JSON
160
161
------------------
@@ -187,8 +188,7 @@ JavaScript value or object by using the ``parse()`` method:
187
188
"$scope": {}
188
189
},
189
190
"bin": { "$binary": { "base64": "AQIDBA==", "subType": "00" } }
190
- }`;
191
-
191
+ }`;
192
192
193
193
const doc = EJSON.parse(ejsonStr);
194
194
console.log(doc);
@@ -197,12 +197,12 @@ JavaScript value or object by using the ``parse()`` method:
197
197
:language: none
198
198
:visible: false
199
199
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
+ }
206
206
207
207
.. note::
208
208
0 commit comments