1BSON_ARRAY_AS_JSON(3)               libbson              BSON_ARRAY_AS_JSON(3)
2
3
4

SYNOPSIS

6          char *
7          bson_array_as_json (const bson_t *bson, size_t *length);
8

PARAMETERS

10bson: A bson_t.
11
12length: An optional location for the length of the resulting string.
13

DESCRIPTION

15       The  bson_array_as_json()  function shall encode bson as a UTF-8 string
16       using libbson's legacy JSON format, except the outermost element is en‐
17       coded  as  a  JSON array, rather than a JSON document. This function is
18       superseded     by      bson_array_as_canonical_extended_json()      and
19       bson_array_as_relaxed_extended_json(),  which  use the same MongoDB Ex‐
20       tended JSON format as all other MongoDB drivers.  The caller is respon‐
21       sible  for  freeing  the  resulting  UTF-8  encoded  string  by calling
22       bson_free() with the result.
23
24       If non-NULL, length will be set to the length of the result in bytes.
25

RETURNS

27       If successful, a newly allocated UTF-8 encoded  string  and  length  is
28       set.
29
30       Upon failure, NULL is returned.
31

EXAMPLE

33          #include <bson/bson.h>
34
35          int main ()
36          {
37             bson_t bson;
38             char *str;
39
40             bson_init (&bson);
41             /* BSON array is a normal BSON document with integer values for the keys,
42              * starting with 0 and continuing sequentially
43              */
44             BSON_APPEND_UTF8 (&bson, "0", "foo");
45             BSON_APPEND_UTF8 (&bson, "1", "bar");
46
47             str = bson_array_as_json (&bson, NULL);
48             /* Prints
49              * [ "foo", "bar" ]
50              */
51             printf ("%s\n", str);
52             bson_free (str);
53
54             bson_destroy (&bson);
55          }
56

AUTHOR

58       MongoDB, Inc
59
61       2017-present, MongoDB, Inc
62
63
64
65
661.25.1                           Nov 08, 2023            BSON_ARRAY_AS_JSON(3)
Impressum