#serde-json #json #value #serde

json_value_search

Interface to search elements into serde_json::Value

9 releases (3 stable)

1.1.0 Jan 11, 2025
1.0.1 Dec 17, 2021
0.1.3 Dec 7, 2021
0.1.1 Sep 28, 2020
0.1.0 Aug 30, 2020

#852 in Encoding

Download history 1/week @ 2024-10-09 2/week @ 2024-10-30 8/week @ 2024-11-06 3/week @ 2024-12-04 20/week @ 2024-12-11 5/week @ 2024-12-18 158/week @ 2025-01-08 9/week @ 2025-01-15

167 downloads per month
Used in chewdata

MIT/Apache

14KB
94 lines

json_value_search

Actions Status semantic-release

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

Getting Started

Installation

Add the following line to your Cargo.toml:

[dependencies]
env_applier = "x.y.z" # Replace with the latest version

Quick Start

Basic Example

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


Contributing

Contributions are welcome!

To contribute:

  1. Fork the repository and create your branch (git checkout -b feature/my-feature).
  2. Commit your changes (git commit -m 'Add some feature').
  3. Push to the branch (git push origin feature/my-feature).
  4. Open a pull request.

For major changes, please open an issue first to discuss your proposal.

Please ensure that tests are added or updated as appropriate.


License

Licensed under either of the following, at your option:

Dependencies

~2.5–4MB
~73K SLoC