Skip to content

Resolve JSON paths for checking rules #55

@martonvago

Description

@martonvago

Rules apply to a specific target. We need to resolve the target before we can execute the rule. By resolving the target I mean finding all direct JSON paths matched by the target and the values at those paths. We want the direct paths as well because we want to include them in the issues we raise.

Task

Given a target JSON path, which can include JSON path selectors like a wildcard (e.g., $.resources[*].name), and a descriptor, find all direct JSON paths in the descriptor that match the target as well as all values at those paths.

For example, $.resources[*].name should resolve to [("$.resources[0].name", "a-resource"), ("$.resources[1].name", "another-resource"), ...], at least conceptually.

python-jsonpath should be able to do this. Look at, e.g., the JSONPathMatch class.

Output

A function like resolve_target(target: str, descriptor: dict[str, Any]) -> list[tuple[str, Any]] or resolve_target(target: str, descriptor: dict[str, Any]) -> list[jsonpath.match.JSONPathMatch]. How to express the matches returned is up for discussion.

Maybe this will just be one function call in python-jsonpath.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions