Function jupiter::ig::json::list_to_doc
source · pub fn list_to_doc(list: &[Value]) -> Result<Doc>
Expand description
Transforms the given list of JSON objects 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_string": "Test1" }, { "a_string": "Test2" }, 42 ]"#;
let value: Value = serde_json::from_str(input).unwrap();
let doc = list_to_doc(value.as_array().unwrap()).unwrap();
assert_eq!(doc.root().len(), 4);
assert_eq!(doc.root().at(1).query("a_string").as_str().unwrap(), "Test1");