2025-01-06 07:03:00
github.com
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.
Keep your files stored safely and securely with the SanDisk 2TB Extreme Portable SSD. With over 69,505 ratings and an impressive 4.6 out of 5 stars, this product has been purchased over 8K+ times in the past month. At only $129.99, this Amazon’s Choice product is a must-have for secure file storage.
Help keep private content private with the included password protection featuring 256-bit AES hardware encryption. Order now for just $129.99 on Amazon!
Support Techcratic
If you find value in Techcratic’s insights and articles, consider supporting us with Bitcoin. Your support helps me, as a solo operator, continue delivering high-quality content while managing all the technical aspects, from server maintenance to blog writing, future updates, and improvements. Support Innovation! Thank you.
Bitcoin Address:
bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge
Please verify this address before sending funds.
Bitcoin QR Code
Simply scan the QR code below to support Techcratic.
Please read the Privacy and Security Disclaimer on how Techcratic handles your support.
Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.