Skip to content

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

Open
@aDotInTheVoid

Description

@aDotInTheVoid

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.

Metadata

Metadata

Assignees

Labels

A-rustdoc-jsonArea: Rustdoc JSON backendA-testsuiteArea: The testsuite used to check the correctness of rustcC-enhancementCategory: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions