| 433 |
433 |
| 434 /** |
434 /** |
| 435 * The JSON writer settings. |
435 * The JSON writer settings. |
| 436 */ |
436 */ |
| 437 struct cx_json_writer_s { |
437 struct cx_json_writer_s { |
| |
438 /** |
| |
439 * Set true to enable pretty output. |
| |
440 */ |
| 438 bool pretty; |
441 bool pretty; |
| |
442 /** |
| |
443 * Set false to output the members in the order in which they were added. |
| |
444 */ |
| 439 bool sort_members; |
445 bool sort_members; |
| |
446 /** |
| |
447 * The maximum number of fractional digits in a number value. |
| |
448 */ |
| 440 uint8_t frac_max_digits; |
449 uint8_t frac_max_digits; |
| |
450 /** |
| |
451 * Set true to use spaces instead of tab characters. |
| |
452 * Indentation is only used in pretty output. |
| |
453 */ |
| 441 bool indent_space; |
454 bool indent_space; |
| |
455 /** |
| |
456 * If \c indent_space is true, this is the number of spaces per tab. |
| |
457 * Indentation is only used in pretty output. |
| |
458 */ |
| 442 uint8_t indent; |
459 uint8_t indent; |
| |
460 /** |
| |
461 * Set true to enable automatic wrapping of arrays. |
| |
462 * Wrapping is only used in pretty output. |
| |
463 * Objects within arrays are always wrapped. |
| |
464 */ |
| 443 bool wrap_array; |
465 bool wrap_array; |
| |
466 /** |
| |
467 * Specify the maximum number of characters in a line before an array needs to wrap. |
| |
468 */ |
| 444 uint16_t wrap_threshold; |
469 uint16_t wrap_threshold; |
| 445 }; |
470 }; |
| 446 |
471 |
| 447 /** |
472 /** |
| 448 * Typedef for the json writer. |
473 * Typedef for the json writer. |
| 449 */ |
474 */ |
| 450 typedef struct cx_json_writer_s CxJsonWriter; |
475 typedef struct cx_json_writer_s CxJsonWriter; |
| 451 |
476 |
| |
477 /** |
| |
478 * Creates a default writer configuration for compact output. |
| |
479 * |
| |
480 * @return new JSON writer settings |
| |
481 */ |
| |
482 cx_attr_nodiscard |
| |
483 CxJsonWriter cxJsonWriterCompact(void); |
| |
484 |
| |
485 /** |
| |
486 * Creates a default writer configuration for pretty output. |
| |
487 * |
| |
488 * @param use_spaces false if you want tabs, true if you want four spaces instead |
| |
489 * @return new JSON writer settings |
| |
490 */ |
| |
491 cx_attr_nodiscard |
| |
492 CxJsonWriter cxJsonWriterPretty(bool use_spaces); |
| 452 |
493 |
| 453 /** |
494 /** |
| 454 * Writes a JSON value to a buffer or stream. |
495 * Writes a JSON value to a buffer or stream. |
| 455 * |
496 * |
| 456 * This function blocks until all data is written or an error when trying |
497 * This function blocks until all data is written or an error when trying |