# JSON (`std/json.zc`) The `std/json` module provides a DOM-style JSON parser and builder. ## Usage ```zc import "std/json.zc" ``` ## Types ### Struct `JsonValue` Represents a node in a JSON document. #### Creation Methods - **`fn null() -> JsonValue`**, **`fn null_ptr() -> JsonValue*`** - **`fn bool(b: bool) -> JsonValue`**, **`fn bool_ptr(b: bool) -> JsonValue*`** - **`fn number(n: double) -> JsonValue`**, **`fn number_ptr(n: double) -> JsonValue*`** - **`fn string(s: char*) -> JsonValue`**, **`fn string_ptr(s: char*) -> JsonValue*`** - **`fn array() -> JsonValue`**, **`fn array_ptr() -> JsonValue*`** - **`fn object() -> JsonValue`**, **`fn object_ptr() -> JsonValue*`** #### Parsing - **`fn parse(json: char*) -> Result`** Parses a JSON string into a heap-allocated `JsonValue` tree. #### Accessors - **`fn is_null(self) -> bool`**, **`is_bool`**, **`is_number`**, **`is_string`**, **`is_array`**, **`is_object`** Check the type of the value. - **`fn as_string(self) -> Option`** Returns `Some(string)` if the value is a string, `None` otherwise. - **`fn as_int(self) -> Option`** - **`fn as_float(self) -> Option`** - **`fn as_bool(self) -> Option`** #### Object/Array Operations - **`fn push(self, val: JsonValue)`** Appends a value to an array. - **`fn set(self, key: char*, val: JsonValue)`** Sets a key-value pair in an object. - **`fn get(self, key: char*) -> Option`** Retrieves a value from an object by key. - **`fn at(self, index: usize) -> Option`** Retrieves a value from an array by index. #### Memory Management - **`fn free(self)`** Recursively frees the JSON value and all its children.