serde-value-utils

Build Status Latest version Documentation License

Bundle of tools to use with serde_value.

Quickstart

You can start using it by first adding it to your Cargo.toml:

toml [dependencies] serde = "1.0" serde_derive = "1.0" serde_value_utils = "0.1"

Then, create a structure which implement the serde::Serialize trait and use it with any serde lib.

Example: toflattenmaptree

```rust

[macro_use]

extern crate serdederive; extern crate serdejson; extern crate serdevalueutils;

[derive(Serialize, Clone, Debug)]

struct SubFoo { a: String, b: u64, }

[derive(Serialize, Clone, Debug)]

struct Foo { a: String, b: f64, c: Vec, d: SubFoo, }

fn main() { let foo = Foo { a: "test".into(), b: 0.5, c: vec![5, 9], d: SubFoo { a: "subtest".into(), b: 695217 } }; let ser = serdevalueutils::toflattenmaptree("", Some(""), &foo).unwrap(); println!("{}", serdejson::tostringpretty(&ser).unwrap()); } **Output**: json { "a": "test", "b": 0.5, "c0": 5, "c1": 9, "da": "subtest", "d_b": 695217 } ```

Feature with-schema

The feature with-schema allow to suffix fields names to suits to the LDP naming conventions.

In your Cargo.toml, set:

toml [dependencies] serde_value_utils = { version = "0.1", features = ["with-schema"] }

Re-run the previous example, and now the output will be :

json { "_a": "test", "_b_float": 0.5, "_c_0_long": 5, "_c_1_long": 9, "_d_a": "subtest", "_d_b_double": 695217 }

Example: trydetecttype

```rust extern crate serdevalueutils;

use serdevalueutils::trydetecttype;

fn main() { println!("{:?}", trydetecttype("6.5")); } **Output**: rust F64(6.5) ```

License: BSD-3-Clause