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
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.