pub struct Json;Expand description
A lightweight, zero-dependency JSON extractor designed for maximum performance.
This struct provides a “fast-path” for parsing JSON response bodies without the overhead of full serialization libraries like Serde. It operates directly on string slices, making it ideal for high-speed CLI tools.
§Dependencies
- Uses only the Rust Standard Library (
std). - Network operations are handled by native-tls.
Implementations§
Source§impl Json
impl Json
Sourcepub fn extract(body: &str, path: &str) -> String
pub fn extract(body: &str, path: &str) -> String
Extracts a value from a JSON string using dot-notation.
This method is format-agnostic, handling both minified and “pretty-printed” JSON by ignoring whitespace and tracking bracket depth to handle nested objects.
§Path Syntax
- Keys:
metadata.version - Arrays:
releases.0.v
§Performance
Operates in O(N) time with minimal heap allocations.
§Returns
Returns the value as an owned String, or "N/A" if the key is not found.
§Example
use crator::Json;
let body = r#"{"stats": {"downloads": 56000}}"#;
let val = Json::extract(body, "stats.downloads");
assert_eq!(val, "56000");Sourcepub fn extract_int(body: &str, path: &str) -> i64
pub fn extract_int(body: &str, path: &str) -> i64
Attempts to parse the extracted value as an i64.
Returns 0 if extraction or parsing fails.
Sourcepub fn extract_u64(body: &str, path: &str) -> u64
pub fn extract_u64(body: &str, path: &str) -> u64
Attempts to parse the extracted value as a u64.
Returns 0 if extraction or parsing fails.
Sourcepub fn extract_float(body: &str, path: &str) -> f64
pub fn extract_float(body: &str, path: &str) -> f64
Attempts to parse the extracted value as an f64.
Returns 0.0 if extraction or parsing fails.
Sourcepub fn extract_bool(body: &str, path: &str) -> bool
pub fn extract_bool(body: &str, path: &str) -> bool
Attempts to parse the extracted value as a bool.
Returns true if the extracted value is “true” (case-insensitive).