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 intoValueobjects. - get_
as_ bytes - Retrieves bytes from a JSON object under a specific key. Combines
get_keyandget_bytesto extract and convert the value. ReturnsNoneif the key doesn’t exist or conversion fails. - get_
as_ json_ string - Retrieve a key and convert it to a JSON string. Returns
Noneif 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_stringandget_as_json_stringto 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
Noneif theValueis 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. ReturnsNonefor unsupported types. Differs fromget_as_bytesby operating directly on theValuerather than extracting from an object key. - get_key
- Retrieves the value associated with a key from a JSON object. Returns
Noneif theValueis not an object or the key doesn’t exist. Differs from type-specific getters likeget_as_stringby returning the rawValue. - get_
key_ from_ json_ string - Retrieves the value associated with a key from a JSON string representing
an object. Combines
from_json_stringandget_keyto parse and extract the value. Returns an error if parsing fails. - get_
string - Retrieve a key and convert it to a String. Returns
Noneif 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
Valueto 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 fromto_plain_stringby applying HTML form conventions (e.g., bool handling). - to_
plain_ string - Converts a
Valueto a plain string representation. Supports String, Number, Bool, and Null types. Returns an error for unsupported types like Array or Object. Differs fromto_html_form_stringby providing a generic string conversion without HTML-specific handling.