Skip to main content

query_single

Function query_single 

Source
pub fn query_single(
    doc: &Document,
    path: &str,
    config: &QueryConfig,
) -> QueryResult<Value>
Expand description

Query a HEDL document and return a single expected match

Returns an error if the query returns zero or multiple results.

§Arguments

  • doc - The HEDL document to query
  • path - JSONPath expression
  • config - Query configuration

§Returns

The single matching JSON value

§Errors

Returns error if zero or multiple matches found

§Examples

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

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

let result = query_single(&doc, "$.name", &config)?;
assert_eq!(result.as_str(), Some("Alice"));
# Ok(())
# }