Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
T

tjq

> 编程语言
Open source

Giving types to jq

197 stars0 likes1 views
WebsiteGitHub

About

Giving types to jq

Typed JQ

tjq is a prototype type inference procedure for jq programs. It requires no annotations, while performing a lightweight inference procedure for jq programs in order to produce better error messages.

JQ is a successful tool for json manipulation.

bash
$ jq -nc '[1, 2, 3] | map(select(. % 2 == 1))'
> [1, 3]

A major shortcoming of jq, often mentioned by practitioners, is its error messages and debugging capabilities. A jq program typically takes a large set of json inputs, transforms and processes these inputs through a set of filters(programs), and produces a set of resulting values. jq interpreter does not keep track of the dataflow through the program, resulting in local errors. Such local errors give us a micro picture of the problem, but fails to inform us of the why. Below is a simple demonstration.

json
[{"name": "John", "age": 25}, {"name": "Jane", "age": 30}]

The following jq program gets traverses the top level array, accesses both name and age fields, and creates an object by accessing the a field of the produced values.

jq
.[] | .age, .name | {v: .a}

This program is false though, name is a string, age is a number, they don't have a field a. When we run the program, we get the following error from jq:

bash
jq: error (at ): Cannot index number with string "a"

Using tjq, we can get a much better global error message:

Shape mismatch detected!
        at [0].age
        Expected: {a: <>}
        Got: 25

As we process the jq program, we build up a shape, a semi-concrete JSON with holes. [{age: {a: <>}, name: {a: <>}}]. After we build up the shape, we can now compare the shape with the input to get global errors.

Installation of the CLI

You can install the latest version of tjq by running the following command:

bash
curl --proto '=https' --tlsv1.2 -LsSf https://github.com/alpaylan/tjq/releases/download/v0.0.1/tjq-installer.sh | sh

You can then run the CLI with the following command:

bash
tjq --expression=".[] | .age, .name | {v: .a}" --input='[{"name": {"a": "John"}, "age": "alp"}, {"name": "Jane", "age": 30}]'

The CLI currently only supports 4 flags:

  • (--expression) and (--path) for providing the jq program.
  • (--input) and (--input-path) for providing the input json.

You can also use --help or -h to get more information about the flags.

If the project is interesting to you, please checkout docs.md, and leave a star!

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Rust

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言