pub fn extract(args: &HashMap<String, Value>) -> Result<Value>
Expand description
Extract from a list of object, the attributes with the values. Keep the object structure.
§Arguments
from
- The list of objects or an object.attributes
- The list of attribute to extract. Accept regular expression in the attribute names.
§Examples
use std::collections::HashMap;
use serde_json::value::Value;
use chewdata::updater::tera_helpers::function::object::extract;
let from = serde_json::from_str::<Value>(r#"[{"field1_1":{"field1_2":"value1_1"}},{"field2_1":{"field2_2":"value2_1"}}]"#).unwrap();
let mut args = HashMap::new();
args.insert("from".to_string(), from);
args.insert("attributes".to_string(), Value::Array(vec![Value::String("field1_1.field1_2".to_string())]));
let result = extract(&args);
assert!(result.is_ok());
assert_eq!(
serde_json::from_str::<Value>(r#"[{"field1_1":{"field1_2":"value1_1"}}]"#).unwrap(),
result.unwrap()
);