224 |
225 |
225 int cxJsonWrite(void* target, const CxJsonValue* value, |
226 int cxJsonWrite(void* target, const CxJsonValue* value, |
226 cx_write_func wfunc, const CxJsonWriter* settings); |
227 cx_write_func wfunc, const CxJsonWriter* settings); |
227 ``` |
228 ``` |
228 |
229 |
229 <warning> |
230 A JSON value can be formatted with the `cxJsonWrite()` function. |
230 TODO: document |
231 |
231 </warning> |
232 The `target` can be a stream, a UCX [buffer](buffer.h.md), or anything else that can be written to with a write function. |
|
233 The behavior of the function is controlled via a `CxJsonWriter` struct. |
|
234 With the functions `cxJsonWriterCompact()` and `cxJsonWriterPretty()` you can create default settings, |
|
235 which you may modify to suit your needs. |
|
236 |
|
237 | Setting | Compact Default | Pretty Default | Description | |
|
238 |-------------------|-----------------|----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
|
239 | `pretty` | `false` | `true` | If true, the JSON will be formatted with line breaks and tabs or spaces. If false, output is as compact as possible without extra characters. | |
|
240 | `sort_members` | `true` | `true` | If false members are written in the order in which they were added. If true, they are sorted lexicographically. | |
|
241 | `frac_max_digits` | 6 | 6 | The maximum number of fractional digits in a number value. | |
|
242 | `indent_space` | ignored | depends on `use_spaces` argument | If true, use spaces for indentation, otherwise use tabs. | |
|
243 | `indent` | ignored | 4 | If `indent_space` is `true`, this is the number of spaces per tab. Ignored otherwise. | |
|
244 | `escape_slash` | `false` | `false` | If `true`, the slash character (a.k.a forward solidus: `/`) is also escaped. This is usually only needed when you want to use JSON as part of an HTML attribute. | |
|
245 |
232 |
246 |
233 <seealso> |
247 <seealso> |
234 <category ref="apidoc"> |
248 <category ref="apidoc"> |
235 <a href="https://ucx.sourceforge.io/api/json_8h.html">json.h</a> |
249 <a href="https://ucx.sourceforge.io/api/json_8h.html">json.h</a> |
236 </category> |
250 </category> |