decamelize-keys 0.1.0

Recursively convert the keys of a JSON object from camelCase to a separated lower-case (e.g. fooBar -> foo_bar). A faithful port of the decamelize-keys npm package.
Documentation
  • Coverage
  • 100%
    8 out of 8 items documented2 out of 8 items with examples
  • Size
  • Source code size: 30.45 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 378.75 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 5s Average build duration of successful builds.
  • all releases: 5s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • trananhtung/decamelize-keys
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • trananhtung

decamelize-keys

All Contributors

crates.io docs.rs CI license

Convert the keys of a JSON object from camelCase to a separated lower-case form.

{ "fooBar": 1 }{ "foo_bar": 1 }. A faithful Rust port of the decamelize-keys npm package, operating on [serde_json::Value] and built on the decamelize crate. It is the inverse of camelcase-keys.

  • deep, custom separator, and exclude options
  • Differential-tested against the reference decamelize-keys implementation (60k cases)

Install

[dependencies]
decamelize-keys = "0.1"
serde_json = "1"

Usage

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 into nested objects and arrays:
assert_eq!(
    decamelize_keys_with(&json!({ "fooBar": { "nestedKey": 1 } }), &Options::new().deep(true)),
    json!({ "foo_bar": { "nested_key": 1 } })
);

// Custom separator, or exclude keys:
assert_eq!(
    decamelize_keys_with(&json!({ "fooBar": 1 }), &Options::new().separator("-")),
    json!({ "foo-bar": 1 })
);
let _ = decamelize_keys_with(&json!({ "apiKey": "x" }), &Options::new().exclude(["apiKey"]));

The exclude option compares against the original keys.

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.