json-schema-validator icon indicating copy to clipboard operation
json-schema-validator copied to clipboard

findJsonNode not working if validationmessage path is "$"

Open kuldeeparora89 opened this issue 4 years ago • 2 comments

If validation message is at the root, then findJsonNode implementation as per link returning below error :

Exception in thread "main" java.lang.IllegalArgumentException: Invalid input: JSON Pointer expression must start with '/': "$"
	at com.fasterxml.jackson.core.JsonPointer.compile(JsonPointer.java:129)
	at com.fasterxml.jackson.core.JsonPointer.valueOf(JsonPointer.java:138)
	at model.jsoneditor.ValidationContext.findJsonNode(ValidationContext.java:43)

Should we add this special condition check to the first line? Sample -

	if("$".equals(msg.getPath())){
			return rootNode;
		}

kuldeeparora89 avatar Jul 03 '21 14:07 kuldeeparora89

There are two specifications for accessing values in a JSON document. Schema Path in networknt closely resembles JSON Pointer spec notation (networknt schema path starts with a "#") and JSON node path resembles JSON Path notation (networknt node path starts with a "$"). Not sure why this was done. But in short you can use "$" to get the root node. @stevehu can give more context here.

prashanthjos avatar Jul 05 '21 14:07 prashanthjos

When we first start the library, both JSON Path and JSON Pointer were not available. That is why I have used a specific notation for the path. I remember it was inspired by one of the popular Javascript libraries at the time. In hindsight, we should adopt JSON Pointer as it is recommended by the specification team.

stevehu avatar Jul 06 '21 03:07 stevehu