std::encoding::jsonJSON parsing and manipulation.
Parse JSON strings into values, inspect their types, extract fields, and convert back to JSON text.
import std::encoding::json;
fn main() {
let val = json.parse("{\"name\": \"Hew\", \"version\": 1}");
let name = val.get_field("name");
println(name.get_string());
name.free();
val.free();
}
parseParse a JSON string into a Value.
Preserves the legacy behavior: invalid JSON returns an invalid handle
(type_of() == -1). Use try_parse for a structured error result.
try_parseParse a JSON string into a Value.
Returns Err(ParseError::Invalid(message)) with the native parser message
when parsing fails. Match on ParseError::Invalid(message) to recover the
original parser message.
ParseErrorStructured error type for JSON parsing failures.
Use Result<Value, ParseError> with try_parse for structured error
handling. Import std::encoding::json when matching on the returned error
value so you can use the existing unqualified
ParseError::Invalid(message) constructor/pattern style.
Invalid(string)The input was not valid JSON. Carries the native parser message.
ValueAn opaque JSON value.
Represents any JSON type: null, bool, integer, float, string, array,
or object. Created by json.parse(s) or by navigating into a
parsed value. Call free() before the value goes out of scope;
dropping without free() is a resource leak.
ValueMethodsMethods available on a JSON Value.
Extends the shared opaque-handle contract from
std::encoding::wire::value_trait. Canonical methods are redeclared here
with JSON-specific docstrings for documentation purposes.
Serialize the value back to a JSON string.
Return the type tag (0=null, 1=bool, 2=i64, 3=float, 4=string, 5=array, 6=object).
Extract the boolean value (0 or 1).
Extract the integer value.
Extract the floating-point value.
Extract the string value.
Look up a field by key in a JSON object.
Return the number of elements in a JSON array.
Return the element at the given index in a JSON array.
Return a JSON array of the object's keys.
Canonical release path for Value.
Callers MUST invoke free() before the value goes out of scope;
dropping without free() is a resource leak.
Set a string field on an object. Returns the object for chaining.
Set an integer field. Returns the object for chaining.
Set a float field. Returns the object for chaining.
Set a boolean field. Returns the object for chaining.
Set a null field. Returns the object for chaining.
Set a Value child on an object. The child is consumed. Returns the object.
Push a Value onto an array. The child is consumed. Returns the array.
Push an integer onto an array. Returns the array.
Push a string onto an array. Returns the array.
Push a float onto an array. Returns the array.
Push a boolean onto an array. Returns the array.
Push null onto an array. Returns the array.