leadpony / justify

Justify is a JSON validator based on JSON Schema Specification and Jakarta JSON Processing API (JSON-P).
Apache License 2.0
96 stars 18 forks source link

Validates schema with random text appended in the end #52

Closed simonmikkelsen closed 4 years ago

simonmikkelsen commented 4 years ago

I create a schema with the following content: {}a As this is invalid json I would expect to get an error when trying to validate it but it parses. I use the 2.1.0 release and runs it like this:

>justify.bat -s schema.json
Validating the schema "schema.json"...
Justified the correctness of the schema "schema.json".

When putting the random text in front of the schema, i.e. a{} I get the expected json parsing error.

simonmikkelsen commented 4 years ago

After researching a work around I found out that this is a feature of most json parsers. To get strict validation of json I ended up parsing the json structure using the example at http://tutorials.jenkov.com/java-json/jackson-jsonparser.html and simply disgarding any output. It will give an exception if there is trailing garbage.