docs/Writerside/topics/json.h.md

changeset 1573
cd2e974410ad
parent 1566
2ebbcb38986d
equal deleted inserted replaced
1572:0499bf03aef3 1573:cd2e974410ad
344 344
345 CxJsonWriter cxJsonWriterPretty(bool use_spaces); 345 CxJsonWriter cxJsonWriterPretty(bool use_spaces);
346 346
347 int cxJsonWrite(void* target, const CxJsonValue* value, 347 int cxJsonWrite(void* target, const CxJsonValue* value,
348 cx_write_func wfunc, const CxJsonWriter* settings); 348 cx_write_func wfunc, const CxJsonWriter* settings);
349
350 cxmutstr cxJsonToString(CxJsonValue *value,
351 const CxAllocator *allocator);
352
353 cxmutstr cxJsonToPrettyString(CxJsonValue *value,
354 const CxAllocator *allocator);
349 ``` 355 ```
350 356
351 A JSON value can be formatted with the `cxJsonWrite()` function. 357 A JSON value can be formatted with the `cxJsonWrite()` function.
352 358
353 The `target` can be a stream, a UCX [buffer](buffer.h.md), or anything else that can be written to with a write function. 359 The `target` can be a stream, a UCX [buffer](buffer.h.md), or anything else that can be written to with a write function.
354 The behavior of the function is controlled via a `CxJsonWriter` struct. 360 The behavior of the function is controlled via a `CxJsonWriter` struct.
355 With the functions `cxJsonWriterCompact()` and `cxJsonWriterPretty()` you can create default settings, 361 With the functions `cxJsonWriterCompact()` and `cxJsonWriterPretty()` you can create default settings,
356 which you may modify to suit your needs. 362 which you may modify to suit your needs (see the table below).
363 The functions `cxJsonToString()` and `cxJsonToPrettyString()` are convenience functions
364 which create a writer with default settings to produce a null-terminated string allocated by the specified allocator.
357 365
358 | Setting | Compact Default | Pretty Default | Description | 366 | Setting | Compact Default | Pretty Default | Description |
359 |-------------------|-----------------|----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------| 367 |-------------------|-----------------|----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
360 | `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. | 368 | `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. |
361 | `frac_max_digits` | 6 | 6 | The maximum number of fractional digits in a number value. | 369 | `frac_max_digits` | 6 | 6 | The maximum number of fractional digits in a number value. |

mercurial