src/cx/json.h

changeset 1077
911a154dd469
parent 1072
c89283cd559b
child 1079
4e1872151fb6
--- a/src/cx/json.h	Wed Jan 01 16:06:32 2025 +0100
+++ b/src/cx/json.h	Thu Jan 02 19:07:56 2025 +0100
@@ -435,12 +435,37 @@
  * The JSON writer settings.
  */
 struct cx_json_writer_s {
+    /**
+     * Set true to enable pretty output.
+     */
     bool pretty;
+    /**
+     * Set false to output the members in the order in which they were added.
+     */
     bool sort_members;
+    /**
+     * The maximum number of fractional digits in a number value.
+     */
     uint8_t frac_max_digits;
+    /**
+     * Set true to use spaces instead of tab characters.
+     * Indentation is only used in pretty output.
+     */
     bool indent_space;
+    /**
+     * If \c indent_space is true, this is the number of spaces per tab.
+     * Indentation is only used in pretty output.
+     */
     uint8_t indent;
+    /**
+     * Set true to enable automatic wrapping of arrays.
+     * Wrapping is only used in pretty output.
+     * Objects within arrays are always wrapped.
+     */
     bool wrap_array;
+    /**
+     * Specify the maximum number of characters in a line before an array needs to wrap.
+     */
     uint16_t wrap_threshold;
 };
 
@@ -449,6 +474,22 @@
  */
 typedef struct cx_json_writer_s CxJsonWriter;
 
+/**
+ * Creates a default writer configuration for compact output.
+ *
+ * @return new JSON writer settings
+ */
+cx_attr_nodiscard
+CxJsonWriter cxJsonWriterCompact(void);
+
+/**
+ * Creates a default writer configuration for pretty output.
+ *
+ * @param use_spaces false if you want tabs, true if you want four spaces instead
+ * @return new JSON writer settings
+ */
+cx_attr_nodiscard
+CxJsonWriter cxJsonWriterPretty(bool use_spaces);
 
 /**
  * Writes a JSON value to a buffer or stream.

mercurial