Skip to main content

Crate oq

Crate oq 

Source
Expand description

oq - Object Query

A jq-like tool for querying JSON, YAML, TOML, and TOON data.

§Example

use oq::{compile_filter, run_filter, parse_auto, encode_to_format, Format};
use serde_json::json;

// Basic query
let filter = compile_filter(".name").unwrap();
let input = json!({"name": "Ada", "age": 30});
let results = run_filter(&filter, input).unwrap();
assert_eq!(results[0], json!("Ada"));

// Parse any format (auto-detected)
let yaml_input = "name: Ada\nage: 30";
let value = parse_auto(yaml_input).unwrap();

// Convert between formats
let toml_output = encode_to_format(&value, Format::Toml).unwrap();

Structs§

ChainMapper
Compose multiple mappers in sequence
CompiledFilter
A compiled jq filter
ContentFormatter
Smart formatter that extracts long content into readable blocks
FieldFormat
Configuration for how to format specific fields
FieldSelectMapper
Mapper that selects specific fields from objects
IdentityMapper
Identity mapper - passes through unchanged
JqMapper
A mapper that uses a jq filter expression
LimitMapper
Mapper that limits array lengths
MapperRegistry
Registry of mappers by tool name pattern
TruncateMapper
Mapper that truncates long strings

Enums§

Format
Internal format representation
InputFormat
Supported input formats
OqError
OutputFormat
Output format options
ToolType
Tool types for smart formatting

Traits§

Mapper
Trait for transforming JSON before TOON encoding

Functions§

command_formatter
Create a formatter configured for command/shell output
compile_filter
Compile a jq filter expression
default_registry
Create a registry with common mappers for typical tool responses
detect_format
Auto-detect format based on content heuristics
encode_table
Encode an array of JSON objects as a compact TOON table
encode_to_format
Convert a JSON value to the specified format
format_content
Format any string content - parses as JSON if possible, then formats as TOON
format_content_smart
Format any string content with smart extraction
format_tool_response
Format a JSON value as TOON, with fallback to JSON string on error
format_tool_response_smart
Format a JSON value as TOON with smart content extraction
format_tool_response_with
Format a tool response with a specific formatter type
json_to_toon
Convert a JSON value to TOON string
json_to_toon_with_mapper
Convert a JSON value to TOON string, applying a mapper first
parse_auto
Parse input with auto-detection
parse_input
Parse input in the detected format
read_note_formatter
Create a formatter configured for read_note tool responses
run_filter
Run a compiled filter on a JSON value
search_formatter
Create a formatter configured for search tool responses
to_json
Convert a JSON value to JSON string
to_toml
Convert a JSON value to TOML string
to_toon
Convert a JSON value to TOON string
to_yaml
Convert a JSON value to YAML string
try_parse_json
Try to parse a string as JSON, returning the parsed value or the original string