#serde-json #json-value #json #value #serde #resolve #resolver

json_value_resolve

Interface to resolve String to serde_json::Value

9 releases (5 stable)

new 1.1.0 Jan 11, 2025
1.0.4 Dec 17, 2021
0.1.2 Dec 6, 2021
0.1.1 Apr 29, 2020

#1682 in Encoding

28 downloads per month
Used in chewdata

MIT/Apache

8KB
90 lines

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());
}

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

Dependencies

~0.4–1MB
~20K SLoC