Skip to content

jsondocck: replace JSONPath with jq as json query language. #142479

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aDotInTheVoid opened this issue Jun 13, 2025 · 5 comments
Open

jsondocck: replace JSONPath with jq as json query language. #142479

aDotInTheVoid opened this issue Jun 13, 2025 · 5 comments
Assignees
Labels
A-rustdoc-json Area: Rustdoc JSON backend A-testsuite Area: The testsuite used to check the correctness of rustc C-enhancement Category: An issue proposing an enhancement or a PR with one. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@aDotInTheVoid
Copy link
Member

aDotInTheVoid commented Jun 13, 2025

Impetus: #142327 (comment)

Currently, jsondocck uses JSONPath to query the output in assertions. Unfortunately, it's not a particularly flexible query language. In particular, it can't feed the result of one query to index an object. We'd really like this, so we can run a query to get an ID, then look up the item with that ID.

Using jq, we can do this. It has an implementation in rust: https://docs.rs/jaq-core/2.2.0/jaq_core/index.html

How

In jsondoc, this place would need to be changed to call into jaq instead.

// FIXME: Make this failible, so jsonpath syntax error has line number.
pub fn select(&self, path: &str) -> Vec<&Value> {
jsonpath_rust::query::js_path_vals(path, &self.value).unwrap()
}

When doing so, the contents of Cache::variables should be provided, so they can be used in selectors.

Test Migration

I think the longest part of this will be migrating the tests from jsonpath to jq. It might be possible to hack up jsondocck to call jsonpath_rust::parser::parse_json_path on all the JSONPath queries, and then convert the JSONPath ast to a equivalent jq query.

I'm not sure if this would be more or less effort than "just" doing it manually. But it'd be easier to review the resulting change this way, and it'd probably be more interesting.

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 13, 2025
@aDotInTheVoid aDotInTheVoid added A-testsuite Area: The testsuite used to check the correctness of rustc T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. A-rustdoc-json Area: Rustdoc JSON backend E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 13, 2025
@aDotInTheVoid
Copy link
Member Author

@fluiderson, you expressed interest in working on this (#142327 (comment)).

Do you still want to? If so, please @ rustbot claim (without the space) to assign it to you. I can't, due to github permissions reasons.

@fmease

This comment has been minimized.

@rustbot rustbot self-assigned this Jun 14, 2025
@fmease fmease added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 15, 2025
@fluiderson
Copy link
Contributor

@rustbot claim

@aDotInTheVoid
Copy link
Member Author

and then convert the JSONPath ast to a equivalent jq query.

https://github.com/jqlang/jq/wiki/For-JSONPath-users is probably a useful start here

@aDotInTheVoid
Copy link
Member Author

Why not something like jq?

See #t-rustdoc > jsondocck @ 💬. The disussion then was entirely about the availibility of rust impls, and not at all about the expressiveness of the query language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rustdoc-json Area: Rustdoc JSON backend A-testsuite Area: The testsuite used to check the correctness of rustc C-enhancement Category: An issue proposing an enhancement or a PR with one. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants