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
valuefromcamelCaseusing the default options (shallow,_). - decamelize_
keys_ with - Convert the keys of
valuefromcamelCasewith the givenOptions.