1BSON_ARRAY_AS_RELAXED_EXTENDED_JSON(3l)ibbsBoSnON_ARRAY_AS_RELAXED_EXTENDED_JSON(3)
2
3
4
6 char *
7 bson_array_as_relaxed_extended_json (const bson_t *bson, size_t *length);
8
10 • bson: A bson_t.
11
12 • length: An optional location for the length of the resulting string.
13
15 The bson_as_relaxed_extended_json() encodes bson as a UTF-8 string in
16 the relaxed MongoDB Extended JSON format, except the outermost element
17 is encoded as a JSON array, rather than a JSON document.
18
19 The caller is responsible for freeing the resulting UTF-8 encoded
20 string by calling bson_free() with the result.
21
22 If non-NULL, length will be set to the length of the result in bytes.
23
25 If successful, a newly allocated UTF-8 encoded string and length is
26 set.
27
28 Upon failure, NULL is returned.
29
31 #include <bson/bson.h>
32
33 int main ()
34 {
35 bson_t bson;
36 char *str;
37
38 bson_init (&bson);
39 /* BSON array is a normal BSON document with integer values for the keys,
40 * starting with 0 and continuing sequentially
41 */
42 BSON_APPEND_DOUBLE (&bson, "0", 3.14);
43 BSON_APPEND_UTF8 (&bson, "1", "bar");
44
45 str = bson_array_as_relaxed_extended_json (&bson, NULL);
46 /* Prints
47 * [ 3.14, "bar" ]
48 */
49 printf ("%s\n", str);
50 bson_free (str);
51
52 bson_destroy (&bson);
53 }
54
56 MongoDB, Inc
57
59 2017-present, MongoDB, Inc
60
61
62
63
641.25.1 Nov 08,B2S0O2N3_ARRAY_AS_RELAXED_EXTENDED_JSON(3)