Repository navigation
Description
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.
rust/src/tools/jsondocck/src/cache.rs
Lines 31 to 34 in 8da6239
| // 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.
Activity
aDotInTheVoid commentedon Jun 13, 2025
@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 commentedon Jun 14, 2025
fluiderson commentedon Jun 15, 2025
@rustbot claim
aDotInTheVoid commentedon Jun 16, 2025
https://github.com/jqlang/jq/wiki/For-JSONPath-users is probably a useful start here
aDotInTheVoid commentedon Jun 16, 2025
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.
nnethercote commentedon Jun 24, 2025
This is also needed for #142945, and the follow-up that will intern strings.
aDotInTheVoid commentedon May 22, 2026
This was discussed at the all hands: rust-lang/all-hands-2026#72
Key Ideas:
hasto work around null issueskohsine commentedon Jun 16, 2026
I'm interested in taking this on if no one else is working on it.
aDotInTheVoid commentedon Jun 17, 2026
No one's working on it, go for it! rust-lang/all-hands-2026#72 (comment) is highly relevant, and useful.
The most important advice is that rewriting all the test assertions is going to be a lot of work. Don't do that until you've got validation that the approach in
jsondocckis correct, or you might waste a load of effort.lolbinarycat commentedon Jul 10, 2026
The directives have been implemented, but they still need to be documented in rustc-dev-guide next to the other jsondocck directives. one thing to note is how
setandjq_setshare a namespace.Rollup merge of rust-lang#158269 - kohsine:add-jq, r=lolbinarycat
Unrolled build for #158269
Rollup merge of #158269 - kohsine:add-jq, r=lolbinarycat