Module serde_value

Source
Expand description

Utilities for working with serde_json::Value objects, including insertion, extraction, and conversion operations.

Functions§

from_json_string
Parses a JSON string into a serde_json::Value. Returns an error if parsing fails. This is a convenience function for deserializing JSON strings into Value objects.
get_as_bytes
Retrieves bytes from a JSON object under a specific key. Combines get_key and get_bytes to extract and convert the value. Returns None if the key doesn’t exist or conversion fails.
get_as_json_string
Retrieve a key and convert it to a JSON string. Returns None if the key doesn’t exist.
get_as_json_string_from_json_string
Retrieves the string value associated with a key from a JSON string representing an object. Combines from_json_string and get_as_json_string to parse and extract the string. Returns an error if parsing fails.
get_as_u64
Retrieves the u64 value associated with a key from a JSON object. Returns None if the Value is not an object, the key doesn’t exist, or the value is not a u64.
get_bytes
Extracts bytes from a Value. Supports arrays of u64 (converted to u8) or base64-encoded strings. Returns None for unsupported types. Differs from get_as_bytes by operating directly on the Value rather than extracting from an object key.
get_key
Retrieves the value associated with a key from a JSON object. Returns None if the Value is not an object or the key doesn’t exist. Differs from type-specific getters like get_as_string by returning the raw Value.
get_key_from_json_string
Retrieves the value associated with a key from a JSON string representing an object. Combines from_json_string and get_key to parse and extract the value. Returns an error if parsing fails.
get_string
Retrieve a key and convert it to a String. Returns None if the key doesn’t exist or is not a string.
insert_key
Inserts a key-value pair into a JSON object. If the input is an object, it adds the key directly. If not, it wraps the input in a new object under “original” and adds the new key. Returns the modified Value.
to_html_form_string
Converts a Value to a string suitable for HTML form fields. Handles Bool as “on” for true or None for false, and supports String, Number, and Null. Returns an error for unsupported types. Differs from to_plain_string by applying HTML form conventions (e.g., bool handling).
to_plain_string
Converts a Value to a plain string representation. Supports String, Number, Bool, and Null types. Returns an error for unsupported types like Array or Object. Differs from to_html_form_string by providing a generic string conversion without HTML-specific handling.