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

NAME

6       bson_array_as_json - bson_array_as_json()
7

SYNOPSIS

9          char *
10          bson_array_as_json (const bson_t *bson, size_t *length);
11

PARAMETERS

13bson: A bson_t.
14
15length: An optional location for the length of the resulting string.
16

DESCRIPTION

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

RETURNS

30       If successful, a newly allocated UTF-8 encoded  string  and  length  is
31       set.
32
33       Upon failure, NULL is returned.
34

EXAMPLE

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

AUTHOR

61       MongoDB, Inc
62
64       2017-present, MongoDB, Inc
65
66
67
68
691.24.3                           Aug 17, 2023            BSON_ARRAY_AS_JSON(3)
Impressum