docs/Writerside/topics/json.h.md

changeset 1267
d17eba9fae33
parent 1258
a12e102ff67f
child 1268
a84403b0a503
equal deleted inserted replaced
1266:a34373b17e58 1267:d17eba9fae33
1 # JSON 1 # JSON
2 2
3 <warning> 3 The UCX JSON API allows [parsing](#parser) and [formatting](#writer) of JSON data.
4 New Feature - will be documented soon! 4
5 </warning> 5 The parser API is similar to the [properties](properties.h.md) parser,
6 but - due to the nature of JSON - is not allocation-free.
6 7
7 ## Parser 8 ## Parser
8 9
9 ```C 10 ```C
10 #include <cx/json.h> 11 #include <cx/json.h>
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>

mercurial