json_value_resolve

Crates.iojson_value_resolve
lib.rsjson_value_resolve
version1.0.4
sourcesrc
created_at2020-04-04 22:19:27.034632
updated_at2021-12-17 21:14:27.37282
descriptionInterface to resolve String to serde_json::Value.
homepage
repositoryhttps://github.com/jmfiaschi/json_value_resolve
max_upload_size
id226423
size19,898
jm.fiaschi (jmfiaschi)

documentation

README

json_value_resolve

Linter Actions Status semantic-release

Give an interface to resolve scalar to json_serde::Value.

Installation

[dependencies]
json_value_resolve = "1.0"

Usage

Resolve scalar to serde_json::value:

extern crate json_value_resolve;

use json_value_resolve::Resolve;

{
  let string_value = "-00010000".to_string();
  let json_value = Value::resolve(string_value);
  assert_eq!(-10000, json_value.as_i64().unwrap());
}

{
  let string_value = "-10.50".to_string();
  let json_value = Value::resolve(string_value);
  assert_eq!(-10.50, json_value.as_f64().unwrap());
}

{
  let string_value = "true".to_string();
  let json_value = Value::resolve(string_value);
  assert_eq!(true, json_value.as_bool().unwrap());
}

{
  let string_object = r#"{"field":"value"}"#.to_string();
  let json_value = Value::resolve(string_object);
  assert_eq!(r#"{"field":"value"}"#, json_value.to_string());
}

{
  let string_value = "null".to_string();
  let json_value = Value::resolve(string_value);
  assert_eq!((), json_value.as_null().unwrap());
}

Useful link

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Apache MIT

Commit count: 16

cargo fmt