pub fn json_value_to_text(v: &serde_json::Value) -> String {
match v {
serde_json::Value::String(s) => s.clone(),
serde_json::Value::Bool(b) => if *b { "t" } else { "f" }.to_string(),
other => other.to_string(),
}
}
pub fn push_flat_rows(
value: serde_json::Value,
out: &mut Vec<serde_json::Map<String, serde_json::Value>>,
) {
match value {
serde_json::Value::Array(items) => {
for item in items {
push_flat_rows(item, out);
}
}
serde_json::Value::Object(mut map) => {
if is_scan_wrapper(&map)
&& let Some(serde_json::Value::Object(inner)) = map.remove("data")
{
out.push(inner);
return;
}
out.push(map);
}
_ => {}
}
}
pub fn is_scan_wrapper(map: &serde_json::Map<String, serde_json::Value>) -> bool {
map.len() == 2
&& matches!(map.get("id"), Some(serde_json::Value::String(_)))
&& matches!(map.get("data"), Some(serde_json::Value::Object(_)))
}