jqesque
A Rust library to parse simplified JSON assignments in a jq-like syntax and convert them into JSON structures.
Sometimes you want to express simplified JSON assignments as strings without writing the full JSON syntax. This library borrows syntax from jq and JSONPath to create a simplified way to represent JSON assignments.
Features
- Nested Objects: Supports nested objects (e.g.,
foo.bar.baz=true). - Arrays with Indices: Supports arrays with indices (e.g.,
foo[0].bar=zoot, where the index must be a positive number). - Boolean, Number, and Null Values: Automatically parses values as booleans, numbers, or null if possible. By default, the value is a string unless serde can parse it as a boolean, number, or null.
- Custom Separators: Scopes can be separated by
Separator::Dot(.),Separator::Slash(/), orSeparator::Custom(char)(custom character).
Values can be anything that serde_json can parse, including strings, numbers, booleans, null, objects, and arrays.
Examples
Basic Usage
use Jqesque;
use json;
Specifying the separator
use ;
use json;
Inserting into an existing JSON structure
use json;
use ;
let mut json_obj = json!;
let input = "settings.theme={\"color\":\"blue\",\"font\":\"Helvetica\"}";
let jqesque = from_str_with_separator.unwrap;
jqesque.insert_into;
let expected = json!;
assert_eq!;
// Note that the "size" key in the original "theme" object is removed.
Merging into an existing JSON structure
use json;
use ;
let mut json_obj = json!;
let input = "settings.theme={\"color\":\"blue\",\"font\":\"Helvetica\"}";
let jqesque = from_str_with_separator.unwrap;
jqesque.merge_into;
let expected = json!;
assert_eq!;
// Note that the "size" key in the original "theme" object is preserved.
License
See the LICENSE file for details.