pub struct SafeJsonValue { /* private fields */ }Expand description
An owned JSON value whose clone, equality, debug formatting, and drop use protected tree operations.
This protection does not extend to arbitrary recursive operations on a
borrowed or extracted serde_json::Value. as_value
returns a shared borrow tied to this owner; callers remain responsible for
the stack behavior of recursive operations they invoke through that borrow.
into_value gives up the protected owner and transfers
responsibility for the resulting tree’s lifetime to the caller.
Serde interoperability uses stacker and still depends on the concrete
serializer or deserializer, which may impose its own recursion limits. The
owner does not enforce an exact heap-memory limit.
Its deserializer accepts i128 and u128 events when their values fit the
JSON integer range, maps None to null, and transparently unwraps Some
and newtype payloads.
The tree protection and the meaning of values produced by Deserialize
are separate concerns. A direct Serde bridge cannot identify whether a
map-shaped event came from an ordinary object or an upstream deserializer’s
private number representation. With serde_json’s arbitrary_precision
feature, number shapes produced by that bridge can therefore differ from
those produced without the feature. When decoding JSON text and preserving
its numeric meaning is important, use JsonDecoder::decode_value_str
(or the corresponding byte and reader methods) instead.
Direct deserialization also rejects duplicate object keys after decoding
their string escapes. It does not normalize Unicode. In contrast,
Self::new takes an existing serde_json::Value as-is: if an upstream
deserializer has already merged duplicate keys, this type cannot recover
them.
§Examples
use qubit_json::value::SafeJsonValue;
use serde_json::json;
let owner = SafeJsonValue::new(json!({"items": [1, 2]}));
let copy = owner.clone();
assert_eq!(owner, copy);
assert_eq!(owner.as_value()["items"][0], 1);
let shallow_raw = copy.into_value();
assert!(shallow_raw.is_object());
assert!(serde_json::from_str::<SafeJsonValue>(r#"{"a":1,"\u0061":2}"#).is_err());Implementations§
Source§impl SafeJsonValue
impl SafeJsonValue
Sourcepub fn as_value(&self) -> &Value
pub fn as_value(&self) -> &Value
Returns a shared borrow of the underlying JSON tree for interoperability.
The returned borrow is tied to this owner. Recursive operations performed through it are the caller’s responsibility and may use the backend’s stack behavior.
§Returns
The underlying tree borrowed for no longer than this owner.
Sourcepub fn into_value(self) -> Value
pub fn into_value(self) -> Value
Transfers the tree and its destruction responsibility to the caller.
The returned Value is no longer protected by this owner; recursive
operations and destruction are the caller’s responsibility.
§Returns
The previously owned JSON tree.