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
//! Integration tests exercising the public API of `decamelize-keys`.

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

#[test]
fn api_payload_to_snake_case() {
    let payload = json!({
        "userId": 1,
        "displayName": "Ada",
        "contactInfo": { "emailAddress": "ada@example.com" }
    });
    assert_eq!(
        decamelize_keys_with(&payload, &Options::new().deep(true)),
        json!({
            "user_id": 1,
            "display_name": "Ada",
            "contact_info": { "email_address": "ada@example.com" }
        })
    );
}

#[test]
fn dash_separator() {
    assert_eq!(
        decamelize_keys_with(&json!({ "backgroundColor": "red" }), &Options::new().separator("-")),
        json!({ "background-color": "red" })
    );
}

#[test]
fn exclude_keys() {
    let opts = Options::new().exclude(["XMLHttpRequest"]);
    assert_eq!(
        decamelize_keys_with(&json!({ "XMLHttpRequest": 1, "fooBar": 2 }), &opts),
        json!({ "XMLHttpRequest": 1, "foo_bar": 2 })
    );
}

#[test]
fn array_of_records() {
    assert_eq!(
        decamelize_keys(&json!([{ "rowId": 1 }, { "rowId": 2 }])),
        json!([{ "row_id": 1 }, { "row_id": 2 }])
    );
}