pub fn parse(value: &Value) -> TableExpand description
The function converts a given Value to a Table.
It’s quite different from json_to_table, cause it is not recursive
and treats json object and array as string values.
let json = serde_json::json!({
"key1": "value1",
"key2": {
"key1": 123,
"key2": [1, 2, 3, 4, 5],
},
"key3": [
{"key": 123.3},
2,
"asd"
],
"key4": 1234.567
});
let table = json_to_table::parse(&json).to_string();
assert_eq!(
table,
concat!(
"+------+---------------------------------+\n",
"| key1 | value1 |\n",
"+------+---------------------------------+\n",
"| key2 | {\"key1\":123,\"key2\":[1,2,3,4,5]} |\n",
"+------+---------------------------------+\n",
"| key3 | [{\"key\":123.3},2,\"asd\"] |\n",
"+------+---------------------------------+\n",
"| key4 | 1234.567 |\n",
"+------+---------------------------------+",
),
)