jsonvalid

Crates.iojsonvalid
lib.rsjsonvalid
version0.1.1
sourcesrc
created_at2018-02-20 11:08:30.198384
updated_at2018-02-20 12:07:36.84082
descriptionValidate JSON files for syntax mistakes using a static binary that can be easily distributed!
homepage
repositoryhttps://github.com/nathankleyn/jsonvalid
max_upload_size
id52024
size22,526
Nathan Kleyn (nathankleyn)

documentation

README

JSON Valid Build Status Crates.io Version Of jsonvalid

Validate JSON files for syntax mistakes using a static binary that can be easily distributed!

Install

You can easily install this using Cargo:

cargo install jsonvalid

Alternatively, you can download a pre-built binary of JSON Valid from the GitHub releases page. Make sure to pick the appropriate static binary for your architecture.

If an architecture of your choice is not available, you don't want to use cargo install, or you want to compile the latest code, you can do a simple cargo build --release in the cloned out version of this repository to get a binary (only stable Rust is required).

Usage

➜  jsonvalid --help
JSON Valid X.Y.Z
Nathan Kleyn <nathan@nathankleyn.com>
Checks whether JSON is valid and well-formed.

USAGE:
    jsonvalid [FILE]...

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

ARGS:
    <FILE>...    files to validate; if none are given, it will read from stdin instead

Examples

Using STDIN

JSON Valid will accept input via STDIN, exiting silently if there are no errors:

➜  echo '{ "foo": "bar" }' | jsonvalid
➜  echo $?
0

If there is an error, you will see detailed information as to where it occurred:

➜  echo '{ "foo": "bar"' | jsonvalid
# => Error in JSON: EOF while parsing an object at line 2 column 0
➜  echo $?
1

Using paths to files

We can also use files instead of STDIN:

➜  echo '{ "foo": "bar" }' > valid.json
➜  echo '{ "foo": "bar"' > invalid.json

If we pass a valid file, we see the same successful, silent exit:

➜  jsonvalid valid.json
➜  echo $?
0

Similarly, an invalid file shows us the cause:

➜  jsonvalid invalid.json
# => Error in file invalid.json: EOF while parsing an object at line 2 column 0
➜  echo $?
1

We can also pass many files. If any of the files is invalid, the whole command fails:

➜  jsonvalid valid.json invalid.json
# => Error in file invalid.json: EOF while parsing an object at line 2 column 0
➜  echo $?
1

Background

I wanted a way to easily validate the well-formedness of JSON files without the following:

  • Obvious syntax errors being allowed (rules out jq, which fails silently with unbalanced braces in <= v1.5).
  • Does not require a runtime or package system to install (rules out jsonlint, which is currently broken and unmaintained anyway!)
  • Does not require me to know about the contents of the JSON (rules out anything that is using JSON schema to achieve the above goals).

Thus, JSON Valid was born!

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Commit count: 8

cargo fmt