oq - Object Query
A jq-like tool for querying and transforming JSON, YAML, TOML, and TOON data.
Features
- Auto-detection: Automatically detects input format (JSON, YAML, TOML, TOON)
- jq syntax: Uses familiar jq filter expressions
- Format conversion: Convert between any supported formats
- Streaming: Reads from files or stdin
Installation
Usage
# Query JSON (like jq)
|
# Output: "Ada"
# Query YAML (auto-detected)
|
# Query TOML
# Output: "oq"
# Convert formats
| | |
# Query and convert
# Raw string output (no quotes)
Options
Usage: oq [OPTIONS] [FILTER] [FILE]...
Arguments:
[FILTER] jq filter expression (default: ".")
[FILE]... Input files (reads from stdin if not specified)
Options:
-i, --input <FORMAT> Input format (auto, json, yaml, toml, toon)
-o, --output <FORMAT> Output format (json, yaml, toml, toon)
-r, --raw Output raw strings without quotes
-c, --compact Compact output (no pretty-printing)
-s, --slurp Read entire input as single array
-n, --null-input Don't read input, use null
--color <WHEN> Colorize output (auto, always, never)
-h, --help Print help
-V, --version Print version
Supported Formats
| Format | Extensions | Description |
|---|---|---|
| JSON | .json |
JavaScript Object Notation |
| YAML | .yaml, .yml |
YAML Ain't Markup Language |
| TOML | .toml |
Tom's Obvious Minimal Language |
| TOON | .toon |
Text Object-Oriented Notation |
Examples
Querying Cargo.toml
# Get package name
# Get all dependencies
# Get dependency versions
Converting Formats
# YAML config to JSON
# JSON API response to YAML
|
# Extract and convert
Filter Expressions
oq uses jaq for jq-compatible filtering:
# Identity (output as-is)
# Select field
# Array index
# Iterate array
# Filter
# Map
# Combine
Library Usage
use ;
// Parse any format
let value = parse_auto?;
// Query with jq expression
let filter = compile_filter?;
let results = run_filter?;
// Convert to another format
let yaml = encode_to_format?;
License
MIT OR Apache-2.0