json_value_search

Crates.iojson_value_search
lib.rsjson_value_search
version1.0.1
sourcesrc
created_at2020-08-30 17:15:44.625772
updated_at2021-12-17 22:01:57.486014
descriptionInterface to search elements into serde_json::Value.
homepage
repositoryhttps://github.com/jmfiaschi/json_value_search
max_upload_size
id282766
size24,983
jm.fiaschi (jmfiaschi)

documentation

README

json_value_search

Actions Status semantic-release

Give an interface to search values into json_serde::Value.

Installation

[dependencies]
json_value_search = "1.0"

Usage

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.+"#));

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: 12

cargo fmt