MyGit

MiSawa/xq

Fork: 18 Star: 324 (更新于 2024-10-20 09:52:01)

license: MIT

Language: Rust .

Pure rust implementation of jq

最后发布版本: v0.4.1 ( 2024-06-30 13:45:29)

GitHub网址

CI crates.io

XQ

JQ reimplemented purely in Rust.

Caution

This program is under development. You probably want to use the original implementation of jq, or pure Go implementation of it called gojq built by itchyny instead, or another Rust implementation called jaq.

Current state

  • Most of the jq components that require syntactical support are, hmm, implemented and tested against queries taken from the jq user manual. Exceptions are imports and module headers.
  • Many builtin functions are missing, include those require intrinsic implementation.
  • Need more unit tests. Most of the CLI options are missing.
  • JSON and YAML formats are supported.

Goals

  • Learn jq.

Ideas

  • Since we use serde to deserialize input / serialize output, we should be able to support any format which has serde implementation (and has multi-document support) without too much effort, except those require scheme (protobuf, thrift, etc.).

  • As a library, we should be able to make anything that implements Serialize as the input type, and anything implements Deserialize as the output type. So in theory, we should be able to write a library that can handle following;

    #[derive(Serialize)]
    struct GitHubRepo {
        user_name: String,
        repo_name: String,
        stars: usize,
    }
    #[derive(Deserialize)]
    struct User {
        name: String,
        total_stars: usize,
    }
    let repos: Vec<GitHubRepo> = fetch_repos();
    let users: Vec<User> = xq::somefunction_slurp<GitHubRepo, User>(repos, r#"
        group_by(.user_name)[]
        | { name: .[0].user_name, total_stars: ([.[].stars] | add) }
    "#).collect();
    

    I mean, it's not something that one should really use. It's just something possible and interesting... isn't it?

Install and run

Are you sure you want to use this??? It's not a daily-usable stage. Though if you want to try, you can install it via

$ cargo install xq
$ cat whatever.json | xq 'query goes here'

. If you'd rather want to download a pre-built binary, either download it manually from the latest release, or use cargo-binstall. Either way, the license texts of the dependencies are in about.html file in the downloaded archive.

You can also clone this repository to your local and run

$ cargo install --path path-to-cloned-dir
$ cat whatever.json | xq 'query goes here'

. Alternatively,

$ cat whatever.json | cargo run -- 'query goes here'

in the cloned directory to try out them without installing.

Uninstall

$ cargo uninstall xq

if you've installed via cargo install. Also remove the cloned directory if you've cloned the repository.

Publish new version

Note for myself.

$ git switch master                 # make sure you're on the master branch
$ cargo release patch               # to dry-run the release
$ cargo release patch --execute     # to actually execute the release

Pass --workspace to publish workspace members as well.

Acknowledgements

  • Although this isn't a direct translation at all, I referred to jq built by Stephen Dolan and gojq built by itchyny. Thank you for the interesting product!

Credits

Author

Mi_Sawa

LICENSE

MIT. Please refer to LICENSE file.

最近版本更新:(数据更新于 2024-09-18 23:45:54)

2024-06-30 13:45:29 v0.4.1

2024-03-05 20:49:36 v0.4.0

2024-02-25 22:05:17 v0.3.1

2024-01-20 09:10:53 v0.3.0

2024-01-15 20:12:26 v0.2.45

2023-05-21 21:39:51 v0.2.44

2023-05-20 22:21:49 v0.2.43

2023-01-27 12:56:22 v0.2.42

2023-01-27 12:39:56 v0.2.41

2022-10-29 14:16:09 v0.2.40

MiSawa/xq同语言 Rust最近更新仓库

2024-11-05 08:48:52 lapce/lapce

2024-11-04 19:47:57 dashpay/platform

2024-11-01 02:26:55 mediar-ai/screenpipe

2024-10-30 06:09:45 electric-capital/crypto-ecosystems

2024-10-29 10:21:58 rustdesk/rustdesk

2024-10-27 15:42:03 jtroo/kanata