Skip to content

Commit c7e6aae

Browse files
committed
JB feedback
1 parent 453d7c4 commit c7e6aae

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

source/data-formats/extended-json.txt

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ Read Extended JSON
2424
------------------
2525

2626
You can read an Extended JSON string into an Ruby array by calling
27-
the ``BSON::ExtJSON.parse()`` method. This method parses an Extended
27+
the ``BSON::ExtJSON.parse`` method. This method parses an Extended
2828
JSON string and returns an array containing the data.
2929

3030
The following example shows how you can read an Extended JSON string into a
31-
array of hashes by using the ``parse()`` method:
31+
array of hashes by using the ``parse`` method:
3232

3333
.. io-code-block::
3434
:copyable:
@@ -51,10 +51,9 @@ array of hashes by using the ``parse()`` method:
5151
Write Extended JSON
5252
-------------------
5353

54-
You can write an Extended JSON string from a hash by using the
55-
``as_extended_json()`` method. By default, this method returns
56-
the Extended JSON string in canonical format, but you can specify relaxed or
57-
legacy formats by passing a ``mode`` argument.
54+
You can write an Extended JSON string by using the ``as_extended_json``
55+
method. By default, this method returns the Extended JSON string in canonical
56+
format, but you can specify relaxed or legacy formats by passing a ``mode`` argument.
5857

5958
.. note:: Legacy Version
6059

@@ -65,9 +64,9 @@ legacy formats by passing a ``mode`` argument.
6564
For more information see, the :manual:`MongoDB Extended JSON v1
6665
</reference/mongodb-extended-json-v1/>` page in the Server manual.
6766

68-
The following example outputs an Extended JSON string in the canonical, relaxed,
69-
and legacy formats. It calls the ``as_extended_json()`` method from inside a
70-
Ruby ``map{}`` block to create the Extended JSON string from an array of hashes:
67+
The ``as_extended_json`` method is available for many other core and
68+
standard library types. The following example creates Extended JSON strings in
69+
the canonical, relaxed, and legacy formats, from an array of hashes:
7170

7271
.. io-code-block::
7372
:copyable:
@@ -94,8 +93,8 @@ For more information, see the following resources:
9493
API Documentation
9594
~~~~~~~~~~~~~~~~~
9695

97-
- `BSON::ExtJSON.parse() <https://www.rubydoc.info/gems/bson/{+bson-version+}/BSON/ExtJSON#parse-class_method>`__
98-
- `#as_extended_json() <https://www.rubydoc.info/gems/bson/{+bson-version+}/BSON/Hash#as_extended_json-instance_method>`__
96+
- `BSON::ExtJSON.parse <https://www.rubydoc.info/gems/bson/{+bson-version+}/BSON/ExtJSON#parse-class_method>`__
97+
- `#as_extended_json <https://www.rubydoc.info/gems/bson/{+bson-version+}/BSON/Array#as_extended_json-instance_method>`__
9998

10099
Server Manual Pages
101100
~~~~~~~~~~~~~~~~~~~

source/includes/data-formats/extended-json.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@
2929
{ "number" => BSON::Int64.new(42) }
3030
]
3131

32-
json_array_canonical = hash_array.map(&:as_extended_json)
33-
json_array_relaxed = hash_array.map{ |hash| hash.as_extended_json(mode: :relaxed) }
34-
json_array_legacy = hash_array.map{ |hash| hash.as_extended_json(mode: :legacy) }
35-
36-
json_string_canonical = JSON.generate(json_array_canonical)
37-
json_string_relaxed = JSON.generate(json_array_relaxed)
38-
json_string_legacy = JSON.generate(json_array_legacy)
32+
json_string_canonical = hash_array.as_extended_json
33+
json_string_relaxed = hash_array.as_extended_json(mode: :relaxed)
34+
json_string_legacy = hash_array.as_extended_json(mode: :legacy)
3935

4036
puts "canonical:\t #{json_string_canonical}"
4137
puts "relaxed:\t #{json_string_relaxed}"

0 commit comments

Comments
 (0)