Handle rendering json arrays and objects
This commit is contained in:
parent
24d2c1831c
commit
7a28e6a9d4
1
js/test_cases/render_unusual_types/input1.json
Normal file
1
js/test_cases/render_unusual_types/input1.json
Normal file
@ -0,0 +1 @@
|
||||
{"name": ["Bob", "Smith"]}
|
1
js/test_cases/render_unusual_types/input2.json
Normal file
1
js/test_cases/render_unusual_types/input2.json
Normal file
@ -0,0 +1 @@
|
||||
{"name": {"first": "Alice", "last": "Jones"}}
|
1
js/test_cases/render_unusual_types/input3.json
Normal file
1
js/test_cases/render_unusual_types/input3.json
Normal file
@ -0,0 +1 @@
|
||||
{"name": ["Bob", {"title": "sir"}, [1,2,3]]}
|
1
js/test_cases/render_unusual_types/main.dust
Normal file
1
js/test_cases/render_unusual_types/main.dust
Normal file
@ -0,0 +1 @@
|
||||
Hello {name}!
|
@ -79,8 +79,13 @@ impl Renderable for serde_json::Value {
|
||||
serde_json::Value::Bool(boolean) => Ok(boolean.to_string()),
|
||||
serde_json::Value::Number(num) => Ok(num.to_string()),
|
||||
serde_json::Value::String(string) => Ok(string.to_string()),
|
||||
serde_json::Value::Array(_arr) => Err(RenderError::CantRender { elem: self }),
|
||||
serde_json::Value::Object(_obj) => Err(RenderError::CantRender { elem: self }),
|
||||
serde_json::Value::Array(arr) => {
|
||||
let rendered: Result<Vec<String>, RenderError> =
|
||||
arr.iter().map(|val| val.render()).collect();
|
||||
let rendered_slice: &[String] = &rendered?;
|
||||
Ok(rendered_slice.join(","))
|
||||
}
|
||||
serde_json::Value::Object(_obj) => Ok("[object Object]".to_owned()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user