pub enum Value {
Null,
Bool(bool),
Number(Number),
String(String),
Array(Vec<Value>),
Object(Object),
}Expand description
A JSON document, with every number kept in its lexical form.
Reading one goes through serde_json’s raw value, so a number arrives with
the precision the document wrote and the crate imposes no
arbitrary_precision feature on anything that depends on it.
Variants§
Null
null.
Bool(bool)
true or false.
Number(Number)
A number.
String(String)
A string.
Array(Vec<Value>)
An array.
Object(Object)
An object.
Implementations§
Source§impl Value
impl Value
Sourcepub fn get(&self, key: &str) -> Option<&Self>
pub fn get(&self, key: &str) -> Option<&Self>
The member named key, None unless this is an object holding it.
Sourcepub const fn as_object(&self) -> Option<&Object>
pub const fn as_object(&self) -> Option<&Object>
The object this holds, None for every other kind.
Sourcepub fn into_serde_json(
self,
path: &mut Path,
) -> Result<Value, ValueConversionError>
pub fn into_serde_json( self, path: &mut Path, ) -> Result<Value, ValueConversionError>
This document as a serde_json::Value, keeping every number exact.
A number converts only when serde_json writes it back in the text
this document carried, so a decimal is never altered on the way out:
FHIR regards 0.010 as different from 0.01
(https://hl7.org/fhir/R4/datatypes.html#decimal). A serde_json
built with arbitrary_precision keeps every lexical form, and one
built without it keeps whole numbers and the decimals f64 writes back
unchanged. Object keys stay in the sorted order Object holds them
in, which carries no meaning: “the order of properties of an object is
not significant in the JSON representation”
(https://hl7.org/fhir/R4/json.html).
§Errors
Returns ValueConversionError naming the element path of the first
number serde_json would alter or cannot hold.
Sourcepub fn to_serde_json(
&self,
path: &mut Path,
) -> Result<Value, ValueConversionError>
pub fn to_serde_json( &self, path: &mut Path, ) -> Result<Value, ValueConversionError>
A copy of this document as a serde_json::Value, keeping every number
exact.
The document is cloned first, so prefer Value::into_serde_json
where the caller owns it. The number rule is the same.
§Errors
Returns ValueConversionError naming the element path of the first
number serde_json would alter or cannot hold.
Sourcepub fn from_serde_json(value: Value) -> Self
pub fn from_serde_json(value: Value) -> Self
A serde_json::Value as this document.
A number arrives in the text serde_json holds for it, which is the
form the document carried when serde_json was built with
arbitrary_precision and the f64 rendering of it otherwise. Read a
FHIR document whose decimals must stay exact through this crate’s own
Value decoder instead; this direction serves the HTTP edge and test
fixtures, where the document is already a serde_json::Value.