Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dougbarth/jsonlint
Checks JSON files for correct syntax and no silly mistakes
https://github.com/dougbarth/jsonlint
Last synced: about 1 month ago
JSON representation
Checks JSON files for correct syntax and no silly mistakes
- Host: GitHub
- URL: https://github.com/dougbarth/jsonlint
- Owner: dougbarth
- License: mit
- Created: 2014-07-03T18:37:50.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2023-04-12T13:34:58.000Z (over 1 year ago)
- Last Synced: 2024-04-25T07:02:15.584Z (8 months ago)
- Language: Ruby
- Size: 48.8 KB
- Stars: 19
- Watchers: 4
- Forks: 18
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-ruby-cli-apps - jsonlint - Lints JSON files. (Awesome Ruby CLIs / Linting)
README
# jsonlint
[![Ruby](https://github.com/dougbarth/jsonlint/actions/workflows/ruby.yml/badge.svg)](https://github.com/dougbarth/jsonlint/actions/workflows/ruby.yml)
[![Gem Version](http://img.shields.io/gem/v/jsonlint.svg)](https://rubygems.org/gems/jsonlint)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## Installation
Add this line to your application's Gemfile:
gem 'jsonlint'
And then execute:
$ bundle
Or install it yourself as:
$ gem install jsonlint
## CLI Usage
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
```## Rake task
You can integrate jsonlint into your build process by adding a Rake task to your project
```ruby
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
```### Rake task options
Add these options similarly to the path option seen above.
| Option | Description | Default |
| ------------- | ------------- | ------------- |
| `exclude_paths` | List of files or paths to exclude from linting | `nil` |
| `fail_on_error` | Continue on to the next rake task when false and don't fail even if JsonLint finds errors | `true` |
| `log_level` | Logger level (DEBUG, INFO, WARN, ERROR, FATAL, or UNKNOWN) | `INFO` |
| `paths` | List of files or paths to lint | `nil` |## Contributing
1. Fork it ( https://github.com/dougbarth/jsonlint/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request