| Crates.io | json_value_search |
| lib.rs | json_value_search |
| version | 1.1.0 |
| created_at | 2020-08-30 17:15:44.625772+00 |
| updated_at | 2025-01-11 23:00:30.318875+00 |
| description | Interface to search elements into serde_json::Value. |
| homepage | |
| repository | https://github.com/jmfiaschi/json_value_search |
| max_upload_size | |
| id | 282766 |
| size | 26,107 |
Give an interface to search values into json_serde::Value.
Add the following line to your Cargo.toml:
[dependencies]
env_applier = "x.y.z" # Replace with the latest version
extern crate json_value_search;
use json_value_search::Search;
use serde_json::Value;
let value: Value = serde_json::from_str(r#"{"field_A":[{"field.B":"value_B"},{"field_C":"value_C"}]}"#).unwrap();
let value_expected_with_wildcard: Value = serde_json::from_str(r#"[{"field.B":"value_B"},{"field_C":"value_C"}]"#).unwrap();
assert_eq!(Some(value_expected_with_wildcard),value.clone().search(r#"/field_A/*"#));
let value_expected_for_specific_field: Value = serde_json::from_str(r#"["value_B"]"#).unwrap();
assert_eq!(Some(value_expected_for_specific_field),value.clone().search(r#"/field_A/*/field.B"#));
let value_expected_for_specific_index: Value = serde_json::from_str(r#"{"field.B":"value_B"}"#).unwrap();
assert_eq!(Some(value_expected_for_specific_index),value.clone().search(r#"/field_A/0"#));
let value_expected_with_regex: Value = serde_json::from_str(r#"["value_B","value_C"]"#).unwrap();
assert_eq!(Some(value_expected_with_regex),value.clone().search(r#"/field_A/*/field.+"#));
Contributions are welcome!
To contribute:
For major changes, please open an issue first to discuss your proposal.
Please ensure that tests are added or updated as appropriate.
Licensed under either of the following, at your option: