Function jupiter::ig::json::object_to_doc
source · pub fn object_to_doc(object: &Map<String, Value>) -> Result<Doc>
Expand description
Transforms a JSON object into a Doc.
The generated Doc will have an object as its root node.
§Errors
This will return an error if we’re running out of symbols (if there are more than 2^31-1 distinct keys in the hash or one of its children).
§Example
let input = r#"{
"a_string": "Test",
"a_map": { "inner_key": 42 },
"a_list": [ 1, 2, { "test": "Plain String" }],
"a_bool": true
}
"#;
let value: Value = serde_json::from_str(input).unwrap();
let doc = object_to_doc(value.as_object().unwrap()).unwrap();
assert_eq!(doc.root().query("a_string").as_str().unwrap(), "Test");