Skip to main content

Module jsonpath

Module jsonpath 

Source
Expand description

JSONPath query engine for extracting specific data. JSONPath query support for HEDL documents

This module provides JSONPath query functionality for HEDL documents, allowing efficient extraction of specific data using standard JSONPath syntax.

§Features

  • Standard JSONPath Syntax: Full support for JSONPath expressions
  • Efficient Queries: Optimized query execution with minimal allocations
  • Type-Safe Results: Returns strongly-typed query results
  • Error Handling: Comprehensive error reporting for invalid queries

§Examples

use hedl_json::jsonpath::{query, QueryConfig};
use hedl_core::Document;

fn example() -> Result<(), Box<dyn std::error::Error>> {
    let doc = hedl_core::parse("name: \"Alice\"\nage: 30".as_bytes())?;
    let config = QueryConfig::default();

    // Simple field access
    let results = query(&doc, "$.name", &config)?;
    assert_eq!(results.len(), 1);

    // Array filtering
    let results = query(&doc, "$.users[?(@.age > 25)]", &config)?;
    Ok(())
}

Structs§

QueryConfig
Configuration for JSONPath queries
QueryConfigBuilder
Builder for constructing QueryConfig instances

Enums§

QueryError
Errors that can occur during JSONPath queries

Functions§

query
Query a HEDL document using JSONPath expression
query_count
Count the number of matches for a JSONPath query
query_exists
Check if a JSONPath query matches any elements in a HEDL document
query_first
Query a HEDL document and return the first match
query_single
Query a HEDL document and return a single expected match

Type Aliases§

QueryResult
Result type for JSONPath queries