camelcase-keys
Convert the keys of a JSON object to camelCase.
{ "foo_bar": 1 } → { "fooBar": 1 }. A faithful Rust port of the widely-used
camelcase-keys npm package, operating on
[serde_json::Value] and built on the camelcase
crate.
deep,pascal_case,preserve_consecutive_uppercase,exclude, andstop_pathsoptions- Numeric-looking keys (
"0","42","3.14","1e3", …) are preserved - Differential-tested against the reference
camelcase-keysimplementation (120k cases)
Install
[]
= "0.1"
= "1"
Usage
use json;
use ;
assert_eq!;
// Recurse into nested objects and arrays:
assert_eq!;
// Exclude keys, stop at paths, or produce PascalCase:
let options = new.deep.exclude.stop_paths;
let _ = camelcase_keys_with;
Notes
- The
excludeandstop_pathsoptions compare against the original keys.stop_pathsuses.-joined original keys. - Built-in caching aside, this port is deterministic: unlike the npm package — whose internal
cache key omits
preserveConsecutiveUppercase, so mixing that option for the same key in a long-lived process can return stale results — this crate always reflects the options you pass.
Contributors ✨
This project follows the all-contributors specification. Contributions of any kind are welcome — code, docs, bug reports, ideas, reviews! See the emoji key for how each contribution is recognized, and open a PR or issue to get involved.
Thanks goes to these wonderful people:
License
Licensed under either of MIT or Apache-2.0 at your option.