#variant #data #query #expressions #json-path #toml #semi-structured

spath

SPath is query expressions for semi-structured data. 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.

3 releases (breaking)

0.2.0 Jan 6, 2025
0.1.0 Jan 6, 2025
0.0.1 Jan 5, 2025

#765 in Parser implementations

Download history 77/week @ 2024-12-30 272/week @ 2025-01-06

349 downloads per month

Apache-2.0

57KB
1K SLoC

SPath: Query expressions for semi-structured data

Crates.io Documentation MSRV 1.75 Apache 2.0 licensed Build Status

Overview

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.

Documentation

Example

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;
use spath::SPath;
use spath::VariantValue;

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

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

Usage

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.

License

This project is licensed under Apache License, Version 2.0.

Dependencies

~1.9–2.6MB
~24K SLoC