pub trait ValueExt {
// Required methods
fn get_str(&self, field: &str) -> Option<String>;
fn get_str_or(&self, field: &str, default: &str) -> String;
fn get_str_required(&self, field: &str) -> Result<String, JacsError>;
fn get_i64(&self, key: &str) -> Option<i64>;
fn get_bool(&self, key: &str) -> Option<bool>;
fn as_string(&self) -> String;
fn get_path(&self, path: &[&str]) -> Option<&Value>;
fn get_path_str(&self, path: &[&str]) -> Option<String>;
fn get_path_str_or(&self, path: &[&str], default: &str) -> String;
fn get_path_str_required(&self, path: &[&str]) -> Result<String, JacsError>;
fn get_path_array(&self, path: &[&str]) -> Option<&Vec<Value>>;
fn get_path_array_required(
&self,
path: &[&str],
) -> Result<&Vec<Value>, JacsError>;
}Expand description
Extension trait for serde_json::Value providing convenient accessor methods.
These helpers reduce boilerplate for common JSON access patterns like:
value.get("field").and_then(|v| v.as_str())->value.get_str("field")value["a"]["b"].as_str().unwrap_or("")->value.get_path_str_or(&["a", "b"], "")value["a"]["b"].as_str().ok_or_else(...)->value.get_path_str_required(&["a", "b"])
Required Methods§
Sourcefn get_str(&self, field: &str) -> Option<String>
fn get_str(&self, field: &str) -> Option<String>
Gets a string field, returning Some(String) if present and a string.
Sourcefn get_str_or(&self, field: &str, default: &str) -> String
fn get_str_or(&self, field: &str, default: &str) -> String
Gets a string field, returning the provided default if missing or not a string.
Sourcefn get_str_required(&self, field: &str) -> Result<String, JacsError>
fn get_str_required(&self, field: &str) -> Result<String, JacsError>
Gets a required string field, returning an error if missing.
Sourcefn get_i64(&self, key: &str) -> Option<i64>
fn get_i64(&self, key: &str) -> Option<i64>
Gets an i64 field, returning Some(i64) if present and numeric.
Sourcefn get_bool(&self, key: &str) -> Option<bool>
fn get_bool(&self, key: &str) -> Option<bool>
Gets a bool field, returning Some(bool) if present and boolean.