1BSON_ARRAY_AS_CANONICAL_EXTENDED_JSONl(i3bB)bSsOoNn_ARRAY_AS_CANONICAL_EXTENDED_JSON(3)
2
3
4
6 bson_array_as_canonical_extended_json - bson_array_as_canonical_ex‐
7 tended_json()
8
10 char *
11 bson_array_as_canonical_extended_json (const bson_t *bson, size_t *length);
12
14 • bson: A bson_t.
15
16 • length: An optional location for the length of the resulting string.
17
19 The bson_array_as_canonical_extended_json() encodes bson as a UTF-8
20 string in the canonical MongoDB Extended JSON format, except the outer‐
21 most element is encoded as a JSON array, rather than a JSON document.
22
23 The caller is responsible for freeing the resulting UTF-8 encoded
24 string by calling bson_free() with the result.
25
26 If non-NULL, length will be set to the length of the result in bytes.
27
29 If successful, a newly allocated UTF-8 encoded string and length is
30 set.
31
32 Upon failure, NULL is returned.
33
35 #include <bson/bson.h>
36
37 int main ()
38 {
39 bson_t bson;
40 char *str;
41
42 bson_init (&bson);
43 /* BSON array is a normal BSON document with integer values for the keys,
44 * starting with 0 and continuing sequentially
45 */
46 BSON_APPEND_INT32 (&bson, "0", 1);
47 BSON_APPEND_UTF8 (&bson, "1", "bar");
48
49 str = bson_array_as_canonical_extended_json (&bson, NULL);
50 /* Prints
51 * [ { "$numberInt" : 1 }, "bar" ]
52 */
53 printf ("%s\n", str);
54 bson_free (str);
55
56 bson_destroy (&bson);
57 }
58
60 MongoDB, Inc
61
63 2017-present, MongoDB, Inc
64
65
66
67
681.24.3 Aug 17B,SO2N0_2A3RRAY_AS_CANONICAL_EXTENDED_JSON(3)