pub enum Json {
Null,
Bool(bool),
Num(f64),
Str(String),
Arr(Vec<Json>),
Obj(BTreeMap<String, Json>),
}Expand description
A JSON value held in memory, as the catalog manipulates it between the file and the model.
Variants§
Null
The null literal, which the catalog uses for an absent or unknown field.
Bool(bool)
The true and false literals.
Num(f64)
A number: JSON knows only one numeric type, kept here as a double.
Str(String)
A text string, already unescaped: the characters it denotes, not its written form.
Arr(Vec<Json>)
An ordered sequence of values, the JSON array; a table of the schema is one of these.
Obj(BTreeMap<String, Json>)
A set of key/value pairs, kept sorted by key so that two writes give the same bytes.
Implementations§
Source§impl Json
impl Json
Sourcepub fn obj() -> Json
pub fn obj() -> Json
Opens an empty object, the starting point for building a row field by field.
Sourcepub fn set(&mut self, key: &str, value: Json)
pub fn set(&mut self, key: &str, value: Json)
Adds or replaces a field. The call is silently ignored when the value is not an object.
Sourcepub fn get(&self, key: &str) -> Option<&Json>
pub fn get(&self, key: &str) -> Option<&Json>
Looks up a field by name; absent key and non-object alike give None, without failing.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Borrows the text of a string value, with no copy; anything else gives None.
Sourcepub fn as_string(&self) -> Option<String>
pub fn as_string(&self) -> Option<String>
Same reading as Json::as_str, copied out for a caller that needs to keep the text.
Sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
Reads an integral, finite count in the u64 range. Fractional and
out-of-range values are refused instead of being rounded or clamped.
Sourcepub fn as_u32(&self) -> Option<u32>
pub fn as_u32(&self) -> Option<u32>
Same reading as Json::as_u64, narrowed for the small counters of the schema such as a
year or a track number.
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Reads a boolean value; a 0 or a "true" string is not accepted as one.
Sourcepub fn as_arr(&self) -> Option<&[Json]>
pub fn as_arr(&self) -> Option<&[Json]>
Borrows the elements of an array, the usual way to walk over the rows of a table.
Sourcepub fn field_str(&self, key: &str) -> Option<String>
pub fn field_str(&self, key: &str) -> Option<String>
Direct access to a typed field, tolerating a missing key.
Sourcepub fn field_u64(&self, key: &str) -> Option<u64>
pub fn field_u64(&self, key: &str) -> Option<u64>
Reads a field as a count, absent or unusable giving None.
Sourcepub fn field_u32(&self, key: &str) -> Option<u32>
pub fn field_u32(&self, key: &str) -> Option<u32>
Reads a field as a small count, absent or unusable giving None.
Sourcepub fn field_f64(&self, key: &str) -> Option<f64>
pub fn field_f64(&self, key: &str) -> Option<f64>
Reads a numeric field that may be fractional.
Sourcepub fn field_optional_bool(&self, key: &str) -> Option<bool>
pub fn field_optional_bool(&self, key: &str) -> Option<bool>
Reads a boolean field, None when it is absent or of another type.
Distinct from Json::field_bool, which answers false for both: an
imported measurement that was never taken is not a measurement that
came out negative.
Sourcepub fn field_bool(&self, key: &str) -> bool
pub fn field_bool(&self, key: &str) -> bool
Reads a flag, where an absent field means false: an older catalog that predates the flag
is read without special handling.
Source§impl Json
impl Json
Sourcepub fn to_string_compact(&self) -> String
pub fn to_string_compact(&self) -> String
Serializes to compact JSON.
Sourcepub fn to_string_pretty(&self) -> String
pub fn to_string_pretty(&self) -> String
Serializes to indented JSON, easier to inspect by hand.