Skip to main content

Crate decamelize_keys

Crate decamelize_keys 

Source
Expand description

§decamelize-keys — convert JSON object keys from camelCase

Recursively convert the keys of a serde_json::Value from camelCase to a separated lower-case form — { "fooBar": 1 }{ "foo_bar": 1 }. A faithful Rust port of the decamelize-keys npm package, built on the decamelize crate. It is the inverse of camelcase-keys.

use serde_json::json;
use decamelize_keys::{decamelize_keys, decamelize_keys_with, Options};

assert_eq!(
    decamelize_keys(&json!({ "fooBar": 1, "BazQux": 2 })),
    json!({ "foo_bar": 1, "baz_qux": 2 })
);

// Recurse with `deep`, or use a custom separator:
assert_eq!(
    decamelize_keys_with(&json!({ "fooBar": { "nestedKey": 1 } }), &Options::new().deep(true)),
    json!({ "foo_bar": { "nested_key": 1 } })
);
assert_eq!(
    decamelize_keys_with(&json!({ "fooBar": 1 }), &Options::new().separator("-")),
    json!({ "foo-bar": 1 })
);

Structs§

Options
Options controlling decamelize_keys_with.

Functions§

decamelize_keys
Convert the keys of value from camelCase using the default options (shallow, _).
decamelize_keys_with
Convert the keys of value from camelCase with the given Options.