百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
T

tjq

> 编程语言
开源

为 jq 赋值类型

197 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

为 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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Rust

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

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