jsonlint checks your JSON files for syntax errors or silly mistakes. Currently it checks for:
- Valid JSON syntax
- Overlapping key definitions in JSON files, where the last definition would win
Add this line to your application's Gemfile:
gem 'jsonlint'
And then execute:
$ bundle
Or install it yourself as:
$ gem install jsonlint
You can run jsonlint against a set of files in the command line. Any errors will be printed and the process will exit with a non-zero exit code.
$ jsonlint spec/data/*
spec/data/deep_overlap.json
The same key is defined twice: foo.bar
spec/data/missing_brace.json
Hash/Object not terminated at line 5, column 2 [sparse.c:782]
spec/data/missing_comma.json
expected comma, not a string at line 3, column 8 [sparse.c:386]
spec/data/overlapping_keys.json
The same key is defined twice: foo
You can integrate jsonlint into your build process by adding a Rake task to your project
require 'jsonlint/rake_task'
JsonLint::RakeTask.new do |t|
t.paths = %w(
spec/**/*.json
)
end
Then run the rake task.
$ rake jsonlint
spec/data/deep_overlap.json
The same key is defined twice: foo.bar
spec/data/missing_brace.json
Hash/Object not terminated at line 5, column 2 [sparse.c:782]
spec/data/missing_comma.json
expected comma, not a string at line 3, column 8 [sparse.c:386]
spec/data/overlapping_keys.json
The same key is defined twice: foo
- Fork it ( https://github.com/PagerDuty/jsonlint/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request