# 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
```bash
cargo install oq
```
## Usage
```bash
# Query JSON (like jq)
# Query YAML (auto-detected)
# Query TOML
oq '.package.name' Cargo.toml
# Output: "oq"
# Convert formats
cat data.json | oq -o toml # JSON -> TOML
# Query and convert
oq '.users[]' data.yaml -o json
# Raw string output (no quotes)
oq -r '.name' data.json
```
## 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
| 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
```bash
# Get package name
oq '.package.name' Cargo.toml
# Get all dependencies
# Get dependency versions
### Converting Formats
```bash
# YAML config to JSON
oq '.' config.yaml -o json > config.json
# JSON API response to YAML
# Extract and convert
oq '.items' data.json -o yaml
```
### Filter Expressions
oq uses [jaq](https://github.com/01mf02/jaq) for jq-compatible filtering:
```bash
# Identity (output as-is)
oq '.'
# Select field
oq '.name'
# Array index
oq '.[0]'
# Iterate array
oq '.[]'
# Filter
# Map
# Combine
## Library Usage
```rust
use oq::{parse_auto, compile_filter, run_filter, encode_to_format, Format};
// Parse any format
let value = parse_auto(r#"{"name": "Ada"}"#)?;
// Query with jq expression
let filter = compile_filter(".name")?;
let results = run_filter(&filter, value)?;
// Convert to another format
let yaml = encode_to_format(&results[0], Format::Yaml)?;
```
## License
MIT OR Apache-2.0