json-path / JsonPath

Java JsonPath implementation
Apache License 2.0
8.93k stars 1.65k forks source link

Support JsonSchema path validation #807

Open Kingnaoufal opened 2 years ago

Kingnaoufal commented 2 years ago

Hi everyone,

In the context of searching values inside a JSON object, the JSON path works fine.

Unfortunately, the usage of searching paths can be dynamic or static. Let's take an example:

Imagine having a configuration file that contains JSON paths to extract data, that was written manually.

A service responsible to compute something loads those configurations at startup in conjunction with some JSON schemas.

This service should do some computation and do some work with the loaded JSON paths on the computed value at that moment we can check if the JSON path is valid or not.

The need is to be able to check if the JSON Path provided at startup is valid just by using JSON schema. It prevents service downtime in the middle of the day and enforces the fail-fast principle as a good practice.

API proposition:

bool isPathValid = JsonPath.validatePath(jsonPath, JsonSchema); List validations = JsonPath.validatePaths(List, JsonSchema);

WDYT guys?

swumao commented 2 years ago

I can't agree more!!

ohapegor commented 2 years ago

I would like to see this feature too.

jotarios commented 1 year ago

In the meanwhile, could this help you?

https://github.com/json-path/JsonPath/issues/577#issuecomment-553795209

antoinedelanglois commented 1 year ago

Hello As @Kingnaoufal , I'm also very interested on a functionality to validate a json path according to a json schema, before getting the json path used on business json data.

Thank you @jotarios for the link. But I think our need goes beyond just validating the json path in itself, since it involves checking if the (valid) json path will be reachable according to the json schema.

Happy to hear if anything came out that would help on this need :) Cheers