-
Notifications
You must be signed in to change notification settings - Fork 455
CDRIVER-4659 Add extended json output capability for bson_array_as_json
#1305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
1b4e77a
add necessary functions to support all types of json output for bson_…
joshbsiegel 4e847a4
consolidate visit_all function using opts
joshbsiegel 5e62a2e
remove changes from bson_json_opts_new to ensure no API break
joshbsiegel 7a3bd55
move new function, add documentation, simplify one line
joshbsiegel c00d565
fix documentation syntax
joshbsiegel 65e8881
add is_outermost_array to opts initializer, minor typos
joshbsiegel 3462a83
fix documentation type
joshbsiegel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
:man_page: bson_array_as_canonical_extended_json | ||
|
||
bson_array_as_canonical_extended_json() | ||
======================================= | ||
|
||
Synopsis | ||
-------- | ||
|
||
.. code-block:: c | ||
|
||
char * | ||
bson_array_as_canonical_extended_json (const bson_t *bson, size_t *length); | ||
|
||
Parameters | ||
---------- | ||
|
||
* ``bson``: A :symbol:`bson_t`. | ||
* ``length``: An optional location for the length of the resulting string. | ||
|
||
Description | ||
----------- | ||
|
||
The :symbol:`bson_array_as_canonical_extended_json()` encodes ``bson`` as a UTF-8 string in the canonical `MongoDB Extended JSON format`_, except the outermost element is encoded as a JSON array, rather than a JSON document. | ||
|
||
The caller is responsible for freeing the resulting UTF-8 encoded string by calling :symbol:`bson_free()` with the result. | ||
|
||
If non-NULL, ``length`` will be set to the length of the result in bytes. | ||
|
||
Returns | ||
------- | ||
|
||
If successful, a newly allocated UTF-8 encoded string and ``length`` is set. | ||
|
||
Upon failure, NULL is returned. | ||
|
||
Example | ||
------- | ||
|
||
.. code-block:: c | ||
|
||
#include <bson/bson.h> | ||
|
||
int main () | ||
{ | ||
bson_t bson; | ||
char *str; | ||
|
||
bson_init (&bson); | ||
/* BSON array is a normal BSON document with integer values for the keys, | ||
* starting with 0 and continuing sequentially | ||
*/ | ||
BSON_APPEND_INT32 (&bson, "0", 1); | ||
BSON_APPEND_UTF8 (&bson, "1", "bar"); | ||
|
||
str = bson_array_as_canonical_extended_json (&bson, NULL); | ||
/* Prints | ||
* [ { "$numberInt" : 1 }, "bar" ] | ||
*/ | ||
printf ("%s\n", str); | ||
bson_free (str); | ||
|
||
bson_destroy (&bson); | ||
} | ||
|
||
|
||
.. only:: html | ||
|
||
.. include:: includes/seealso/bson-as-json.txt | ||
|
||
.. _MongoDB Extended JSON format: https://github.com/mongodb/specifications/blob/master/source/extended-json.rst |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
joshbsiegel marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
:man_page: bson_array_as_relaxed_extended_json | ||
|
||
bson_array_as_relaxed_extended_json() | ||
===================================== | ||
|
||
Synopsis | ||
-------- | ||
|
||
.. code-block:: c | ||
|
||
char * | ||
bson_array_as_relaxed_extended_json (const bson_t *bson, size_t *length); | ||
|
||
Parameters | ||
---------- | ||
|
||
* ``bson``: A :symbol:`bson_t`. | ||
* ``length``: An optional location for the length of the resulting string. | ||
|
||
Description | ||
----------- | ||
|
||
The :symbol:`bson_as_relaxed_extended_json()` encodes ``bson`` as a UTF-8 string in the relaxed `MongoDB Extended JSON format`_, except the outermost element is encoded as a JSON array, rather than a JSON document. | ||
|
||
The caller is responsible for freeing the resulting UTF-8 encoded string by calling :symbol:`bson_free()` with the result. | ||
|
||
If non-NULL, ``length`` will be set to the length of the result in bytes. | ||
|
||
Returns | ||
------- | ||
|
||
If successful, a newly allocated UTF-8 encoded string and ``length`` is set. | ||
|
||
Upon failure, NULL is returned. | ||
|
||
Example | ||
------- | ||
|
||
.. code-block:: c | ||
|
||
#include <bson/bson.h> | ||
|
||
int main () | ||
{ | ||
bson_t bson; | ||
char *str; | ||
|
||
bson_init (&bson); | ||
/* BSON array is a normal BSON document with integer values for the keys, | ||
* starting with 0 and continuing sequentially | ||
*/ | ||
BSON_APPEND_DOUBLE (&bson, "0", 3.14); | ||
BSON_APPEND_UTF8 (&bson, "1", "bar"); | ||
|
||
str = bson_array_as_relaxed_extended_json (&bson, NULL); | ||
/* Prints | ||
* [ 3.14, "bar" ] | ||
*/ | ||
printf ("%s\n", str); | ||
bson_free (str); | ||
|
||
bson_destroy (&bson); | ||
} | ||
|
||
|
||
.. only:: html | ||
|
||
.. include:: includes/seealso/bson-as-json.txt | ||
|
||
.. _MongoDB Extended JSON format: https://github.com/mongodb/specifications/blob/master/source/extended-json.rst |
joshbsiegel marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
:man_page: bson_json_opts_set_outermost_array | ||
|
||
bson_json_opts_set_outermost_array() | ||
==================================== | ||
|
||
Synopsis | ||
-------- | ||
|
||
.. code-block:: c | ||
|
||
void | ||
bson_json_opts_set_outermost_array (bson_json_opts_t *opts, bool is_outermost_array); | ||
|
||
Parameters | ||
---------- | ||
|
||
* ``opts``: A :symbol:`bson_json_opts_t`. | ||
* ``is_outermost_array``: A value determining what we want to set the is_outermost_array variable to. | ||
|
||
Description | ||
----------- | ||
|
||
The :symbol:`bson_json_opts_set_outermost_array()` function shall set the ``is_outermost_array`` variable on the :symbol:`bson_json_opts_t` parameter using the boolean provided. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.