java-json-tools / json-schema-validator

A JSON Schema validation implementation in pure Java, which aims for correctness and performance, in that order
http://json-schema-validator.herokuapp.com/
Other
1.62k stars 399 forks source link

More JSON-friendly report? #157

Open jpblair opened 9 years ago

jpblair commented 9 years ago

I'm planning to use the library to validate data coming in from clients, and on error return the detailed error information. Is there any way to get this in a more JSON-friendly format? For example, having level/schema/instance/etc all be separate JSON fields. Apologies if this already exists and I just haven't found it.

febpetroni commented 9 years ago

:+1: I would also like this. Haven't found it anywhere in the API so far.

rodrigosaito commented 9 years ago

I would love this as well.

@fge are you willing to accept a PR for this?

jpblair commented 9 years ago

@febpetroni @rodrigosaito I was able to find a solution for this after doing some digging around. Each ProcessingMessage in the ProcessingReport has an asJson() method which returns a JsonNode object. I was able to create a JSON array and iterate through each ProcessingMessage, adding its asJson() output to the array. Hope this helps.

nickawatts commented 8 years ago

Another way to do this is to use the ListProcessingReport.

ProcessingReport report = schema.validate(jsonInput, true);
ListProcessingReport listProcessingReport = new ListProcessingReport();
listProcessingReport.mergeWith(report);
System.out.println(listProcessingReport.asJson());

ListProcessingReport has a copy constructor that would cut that code down by a line but it wasn't working for me.