summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-30 23:41:21 +0000
committerZuhaitz Méndez Fernández de Aránguiz <zuhaitz@debian>2026-01-30 23:41:34 +0000
commit422616a43b4f9b7659c96bfffd2f3095461dbea5 (patch)
tree33b52ba91695a1e816b6b5a45be485f603032626 /docs
parent51638176265392c70ca2e0014de95867bac4991e (diff)
JSON serialization
Diffstat (limited to 'docs')
-rw-r--r--docs/std/json.md26
-rw-r--r--docs/std/string.md4
2 files changed, 30 insertions, 0 deletions
diff --git a/docs/std/json.md b/docs/std/json.md
index fba2ad8..ce35d64 100644
--- a/docs/std/json.md
+++ b/docs/std/json.md
@@ -51,6 +51,32 @@ Represents a node in a JSON document.
- **`fn at(self, index: usize) -> Option<JsonValue*>`**
Retrieves a value from an array by index.
+#### Serialization
+
+- **`fn to_string(self) -> String`**
+ Serializes the JSON value to a string representation.
+
+- **`fn stringify(self, buf: String*)`**
+ Internal recursive serialization method that appends to a string buffer.
+
+**Example:**
+```zc
+let obj = JsonValue::object();
+obj.set("name", JsonValue::string("Alice"));
+obj.set("age", JsonValue::number(30.0));
+
+let json_str = obj.to_string();
+println "{json_str.c_str()}"; // {"name":"Alice","age":30}
+json_str.free();
+obj.free();
+```
+
+**Features:**
+- Proper escaping of special characters: `\"`, `\\`, `\n`, `\t`, `\r`, `\b`, `\f`
+- Numbers formatted with `%.15g` for precision
+- Recursive serialization for nested objects and arrays
+- Round-trip compatible with `parse()`
+
#### Memory Management
- **`fn free(self)`**
diff --git a/docs/std/string.md b/docs/std/string.md
index 1f89e0f..a2f63f5 100644
--- a/docs/std/string.md
+++ b/docs/std/string.md
@@ -49,8 +49,12 @@ struct String {
| Method | Signature | Description |
| :--- | :--- | :--- |
| **append** | `append(self, other: String*)` | Appends another string to this one. |
+| **append_c** | `append_c(self, s: char*)` | Appends a C string literal. Uses value receiver. |
+| **append_c_ptr** | `append_c_ptr(ptr: String*, s: char*)` | Appends a C string literal using pointer receiver for guaranteed mutation. |
| **add** | `add(self, other: String*) -> String` | Concatenates this string and another into a new String. |
+**Note:** When passing `String*` to functions that need to mutate, use `append_c_ptr` instead of `append_c` for reliable mutation.
+
### Access & Query
| Method | Signature | Description |