Skip to main content

Crate camelcase_keys

Crate camelcase_keys 

Source
Expand description

§camelcase-keys — convert JSON object keys to camelCase

Recursively convert the keys of a serde_json::Value to camelCase. A faithful Rust port of the widely-used camelcase-keys npm package, built on the camelcase crate.

use serde_json::json;
use camelcase_keys::{camelcase_keys, camelcase_keys_with, Options};

assert_eq!(
    camelcase_keys(&json!({ "foo_bar": 1, "baz-qux": 2 })),
    json!({ "fooBar": 1, "bazQux": 2 })
);

// Recurse into nested objects/arrays with `deep`:
assert_eq!(
    camelcase_keys_with(&json!({ "foo_bar": { "nested_key": 1 } }), &Options::new().deep(true)),
    json!({ "fooBar": { "nestedKey": 1 } })
);

Numeric-looking keys ("0", "42", "3.14", …) are preserved, and the pascal_case, preserve_consecutive_uppercase, exclude, and stop_paths options match the reference.

Structs§

Options
Options controlling camelcase_keys_with.

Functions§

camelcase_keys
Convert the keys of value to camelCase using the default options (shallow).
camelcase_keys_with
Convert the keys of value to camelCase with the given Options.