Skip to content
Latchkey

rq: Convert and Query JSON, YAML, TOML, CBOR

rq (record-query) is a format-converting filter: it reads JSON, YAML, TOML, CBOR, or MessagePack, applies a query, and writes any of those formats back out.

rq is like jq for a wider set of serialization formats. You tell it the input and output formats with flags and pass an optional query, making it a one-stop converter in a pipeline.

What it does

rq streams records from the input format (chosen with an input flag such as -j for JSON or -y for YAML) into a common model, optionally transforms them with a query, and serializes to the output format flag. It handles binary formats like CBOR and MessagePack alongside text ones.

Common usage

Terminal
# JSON in, YAML out
cat config.json | rq -jy
# YAML in, JSON out with a query
cat values.yaml | rq -yj '.image.tag'
# TOML in, JSON out
cat Cargo.toml | rq -tj

Options

FlagWhat it does
-jJSON as input (and output when combined)
-yYAML input/output
-tTOML input/output
-cCBOR input/output
-mMessagePack input/output

In CI

rq is convenient for converting a config to JSON so jq can query it, or the reverse when a step needs YAML. Combine the input and output flags (-jy = JSON to YAML). Because it also reads CBOR and MessagePack, it can decode binary API payloads that jq cannot.

Common errors in CI

A format mismatch (telling rq the input is JSON when it is YAML) yields a decode error like "expected value" or "invalid type". Forgetting to pass an output format prints the default rather than the format you wanted, so always specify both letters. A syntax error in the query is reported before any output is written.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →