flats

Crates.ioflats
lib.rsflats
version0.1.0
sourcesrc
created_at2018-06-25 04:41:04.133825
updated_at2018-06-25 04:41:04.133825
descriptionflattens nested structures into a flat single dimension map
homepagehttps://github.com/softprops/flats
repositoryhttps://github.com/softprops/flats
max_upload_size
id71567
size12,175
cargo (github:rustpq:cargo)

documentation

https://softprops.github.io/flats

README

flats Build Status Coverage Status crates.io docs.rs Master API docs

🥞 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

Commit count: 15

cargo fmt