Skip to main content

Json

Struct Json 

Source
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

Source

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");
Source

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.

Source

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.

Source

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.

Source

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).

Auto Trait Implementations§

§

impl Freeze for Json

§

impl RefUnwindSafe for Json

§

impl Send for Json

§

impl Sync for Json

§

impl Unpin for Json

§

impl UnwindSafe for Json

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.