Sun, 30 Mar 2025 18:21:43 +0200
document JSON writer
relates to #451
docs/Writerside/topics/json.h.md | file | annotate | diff | comparison | revisions |
--- a/docs/Writerside/topics/json.h.md Sat Mar 29 19:58:41 2025 +0100 +++ b/docs/Writerside/topics/json.h.md Sun Mar 30 18:21:43 2025 +0200 @@ -1,8 +1,9 @@ # JSON -<warning> -New Feature - will be documented soon! -</warning> +The UCX JSON API allows [parsing](#parser) and [formatting](#writer) of JSON data. + +The parser API is similar to the [properties](properties.h.md) parser, +but - due to the nature of JSON - is not allocation-free. ## Parser @@ -226,9 +227,22 @@ cx_write_func wfunc, const CxJsonWriter* settings); ``` -<warning> -TODO: document -</warning> +A JSON value can be formatted with the `cxJsonWrite()` function. + +The `target` can be a stream, a UCX [buffer](buffer.h.md), or anything else that can be written to with a write function. +The behavior of the function is controlled via a `CxJsonWriter` struct. +With the functions `cxJsonWriterCompact()` and `cxJsonWriterPretty()` you can create default settings, +which you may modify to suit your needs. + +| Setting | Compact Default | Pretty Default | Description | +|-------------------|-----------------|----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `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. | +| `sort_members` | `true` | `true` | If false members are written in the order in which they were added. If true, they are sorted lexicographically. | +| `frac_max_digits` | 6 | 6 | The maximum number of fractional digits in a number value. | +| `indent_space` | ignored | depends on `use_spaces` argument | If true, use spaces for indentation, otherwise use tabs. | +| `indent` | ignored | 4 | If `indent_space` is `true`, this is the number of spaces per tab. Ignored otherwise. | +| `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. | + <seealso> <category ref="apidoc">