1 unstable release
Uses old Rust 2015
0.1.0 | Jun 25, 2018 |
---|
#1690 in Data structures
10KB
184 lines
flats
🥞 flattens nested structures into a flat single dimension map
📦 install
Add the following to your cargo project's Cargo.toml
file.
[dependencies]
flats = "0.1"
🤸 usage
#[macro_use]
extern crate serde_json;
extern crate flats;
use std::collections::BTreeMap;
use flats::{flatten_value, Scalar};
fn main() {
let flat: BTreeMap<String, Scalar> = flatten_value(
json!({
"name": "John Doe",
"address": {
"city": "nyc"
},
"phones": [
"+44 1234567",
"+44 2345678"
]
})
);
let mut expected: BTreeMap<String, Scalar> = BTreeMap::new();
expected.insert("name".into(), "John Doe".into());
expected.insert("address.city".into(), "nyc".into());
expected.insert("phones[0]".into(), "+44 1234567".into());
expected.insert("phones[1]".into(), "+44 2345678".into());
assert_eq!(expected, flat);
}
Doug Tangren (softprops) 2018
Dependencies
~0.7–1.6MB
~34K SLoC