Crates.io | json_value_resolve |
lib.rs | json_value_resolve |
version | 1.0.4 |
source | src |
created_at | 2020-04-04 22:19:27.034632 |
updated_at | 2021-12-17 21:14:27.37282 |
description | Interface to resolve String to serde_json::Value. |
homepage | |
repository | https://github.com/jmfiaschi/json_value_resolve |
max_upload_size | |
id | 226423 |
size | 19,898 |
Give an interface to resolve scalar to json_serde::Value.
[dependencies]
json_value_resolve = "1.0"
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());
}
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.