How to run json-schema-validator from the command line?

1,037 views
Skip to first unread message

Roger Costello

unread,
Apr 4, 2014, 11:48:12 AM4/4/14
to json-schem...@googlegroups.com
Hi Folks,

Is it possible to run the json-schema-validator from the command line?

Is there a jar file for json-schema-validator? I found a jar at:

     http://mvnrepository.com/artifact/com.github.fge/json-schema-validator/2.1.8

but it appears to be corrupt/incomplete/something (I'm not a Java programmer). Applying java.exe to the jar file:

     java -jar json-schema-validator-2.1.8.jar

results in this error message:

     "no main manifest attribute, in json-schema-validator-2.1.8.jar"

What does that mean?

Here are my questions:

1. Where can I obtain the correct jar file for json-schema-validator?

2. Once I obtain the jar file, how do I use it on a command line to validate a json file against a json-schema file? That is, on the command line I would like to type this:

     java -jar json-schema-validator-2.1.8.jar instance.json schema.json

and have the validator validate instance.json against schema.json and display the results of the validation on the command line.

Thanks!

/Roger

Francis Galiegue

unread,
Apr 4, 2014, 12:07:52 PM4/4/14
to Roger Costello, json-schem...@googlegroups.com
Hello,

On Fri, Apr 4, 2014 at 5:48 PM, Roger Costello <roger.c...@gmail.com> wrote:
> Hi Folks,
>
> Is it possible to run the json-schema-validator from the command line?
>

Currently, no. There is a proposal to add a Gradle app support as a
pull request:

https://github.com/fge/json-schema-validator/pull/81

Unfortunately I haven't had the time to delve into it. Also, my
requests for documentation were left unanswered ;)

The difficulty also resides in the number of dependencies required;
there is an option to create a fatjar which WOULD make a manifest with
"Main-Class" actually useful. But I have yet to test this scenario.
This kind of answers your question below:

> Is there a jar file for json-schema-validator? I found a jar at:
>
>
> http://mvnrepository.com/artifact/com.github.fge/json-schema-validator/2.1.8
>
> but it appears to be corrupt/incomplete/something (I'm not a Java
> programmer). Applying java.exe to the jar file:
>
> java -jar json-schema-validator-2.1.8.jar
>
> results in this error message:
>
> "no main manifest attribute, in json-schema-validator-2.1.8.jar"
>
> What does that mean?
>

1. for a jar to be "executable", you need to have a file named
META-INF/MANIFEST.MF with it with a Main-Class entry "poiting" to a
class with a main() in it; the current jar doesn't have that;
2. even if it had, it wouldn't run since this jar by itself doesn't
include all dependencies.


> Here are my questions:
>
> 1. Where can I obtain the correct jar file for json-schema-validator?
>
> 2. Once I obtain the jar file, how do I use it on a command line to validate
> a json file against a json-schema file? That is, on the command line I would
> like to type this:
>
> java -jar json-schema-validator-2.1.8.jar instance.json schema.json
>
> and have the validator validate instance.json against schema.json and
> display the results of the validation on the command line.
>

Well, as I explained above, right now, can't do... But I think this
would be a good thing to have. Care to open a feature request?

(yeah, I know, the issues are a little messy right now, I've had to
step aside this project for a while but now I'm back on it; 2.2 is in
the pipe and I'll see to it that such a command line tool is included)

--
Francis Galiegue, fgal...@gmail.com
JSON Schema in Java: http://json-schema-validator.herokuapp.com

Francis Galiegue

unread,
Apr 11, 2014, 6:01:50 AM4/11/14
to json-schem...@googlegroups.com


On Friday, April 4, 2014 5:48:12 PM UTC+2, Roger Costello wrote:
Hi Folks,

Is it possible to run the json-schema-validator from the command line?


It is possible starting from 2.1.10!

See the README for the project: https://github.com/fge/json-schema-validator. Basically, download the standalone jar from bintray, rename it if you want (let us say, jsonschema.jar) and then you can use it via the command line:

# run a syntax checking on one or more schemas; brief mode
java -jar jsonschema.jar --syntax schema1.json schema2.json -s
# run a validation on JSON data given a schema
java -jar jsonschema.jar schema.json file1.json file2.json

Hope this helps!
Reply all
Reply to author
Forward
0 new messages