Hackers News

cratesland/spath: Query expressions for semi-structured data

Crates.io
Documentation
MSRV 1.75
Apache 2.0 licensed
Build Status

You can use it as a drop-in replacement for JSONPath, but also for other semi-structured data formats like TOML or user-defined variants.

Here is a quick example that shows how to use the spath crate to query JSONPath alike expression over JSON data:

use serde_json::json;
use serde_json::Value as JsonValue;
use spath::SPath;
use spath::Value;

fn main() {
    let data = json!({
        "name": "John Doe",
        "age": 43,
        "phones": [
            "+44 1234567",
            "+44 2345678"
        ]
    });

    let spath = SPath::new("$.phones[1]").unwrap();
    let value = Value::from(data);
    let result = spath.eval(&value).unwrap();
    assert_eq!(JsonValue::from(result), json!("+44 2345678"));
}

spath is on crates.io and can be used by adding spath to your dependencies in your project’s Cargo.toml. Or more simply, just run cargo add spath.

This project is licensed under Apache License, Version 2.0.

admin

The realistic wildlife fine art paintings and prints of Jacquie Vaux begin with a deep appreciation of wildlife and the environment. Jacquie Vaux grew up in the Pacific Northwest, soon developed an appreciation for nature by observing the native wildlife of the area. Encouraged by her grandmother, she began painting the creatures she loves and has continued for the past four decades. Now a resident of Ft. Collins, CO she is an avid hiker, but always carries her camera, and is ready to capture a nature or wildlife image, to use as a reference for her fine art paintings.

Related Articles

Leave a Reply