1# basic_json::dump 2 3```cpp 4string_t dump(const int indent = -1, 5 const char indent_char = ' ', 6 const bool ensure_ascii = false, 7 const error_handler_t error_handler = error_handler_t::strict) const 8``` 9 10Serialization function for JSON values. The function tries to mimic 11Python's `json.dumps()` function, and currently supports its `indent` 12and `ensure_ascii` parameters. 13 14## Parameters 15 16`indent` (in) 17: If `indent` is nonnegative, then array elements and object 18 members will be pretty-printed with that indent level. An indent level of 19 `0` will only insert newlines. `-1` (the default) selects the most compact 20 representation. 21 22`indent_char` (in) 23: The character to use for indentation if `indent` is 24 greater than `0`. The default is ` ` (space). 25 26`ensure_ascii` (in) 27: If `ensure_ascii` is true, all non-ASCII characters 28 in the output are escaped with `\uXXXX` sequences, and the result consists 29 of ASCII characters only. 30 31`error_handler` (in) 32: how to react on decoding errors; there are three 33 possible values: `strict` (throws and exception in case a decoding error 34 occurs; default), `replace` (replace invalid UTF-8 sequences with U+FFFD), 35 and `ignore` (ignore invalid UTF-8 sequences during serialization; all 36 bytes are copied to the output unchanged). 37 38## Return value 39 40string containing the serialization of the JSON value 41 42## Exception safety 43 44Strong guarantee: if an exception is thrown, there are no 45changes to any JSON value. 46 47## Complexity 48 49Linear. 50 51## Notes 52 53Binary values are serialized as object containing two keys: 54 55- "bytes": an array of bytes as integers 56- "subtype": the subtype as integer or `#!json null` if the binary has no subtype 57 58## Example 59 60??? example 61 62 The following example shows the effect of different `indent`, 63 `indent_char`, and `ensure_ascii` parameters to the result of the 64 serialization. 65 66 ```cpp 67 --8<-- "examples/dump.cpp" 68 ``` 69 70 Output: 71 72 ```json 73 --8<-- "examples/dump.output" 74 ``` 75