Ruby is a beautiful programming language that was designed for programmer productivity. It comes feature-packed with numerous inbuilt classes and methods to make programming enjoyable for developers.
According to Wikipedia, JSON(JavaScript Object Notation) is an open standard file format and data interchange format. It uses human-readable text to store and transmit data objects. JSON files consist of attribute-value pairs and arrays (or other serializable values).
In today's development world, JSON is one of the popular data formats. Although it was derived from JavaScript, it a language-independent format. Many languages come with an inbuilt JSON parser. It is also a light-weight format and, it is human-readable.
This project aims to use some of Ruby's inbuilt methods to build a JSON linter. The project will continue to evolve and be updated. I hope you find it helpful.
This JSON linter checks for the following errors/warnings:
- Check empty line error
- Check for missing/unexpected tags i.e. '( )', '[ ]', and '{ }'
- Check for the wrong indentation
- Check for the malformed fractions
- Check for the leading zeros
- Check new line at end of JSON
Well formed JSON passes the test successfully!
# Well Formed JSON
{
"firstName": "John",
"lastName": "Snow",
"age": 25,
"children": [],
"spouse": null,
"address": {
"street": "7504 Taylor Drive",
"city": "New York City",
},
"phoneNumbers": [
{
"type": "mobile",
"number": "212 555-3346"
}
]
}
Badly formed JSON fails the test
# Badly formed JSON
{
"openObject": {
"improperIndent": "string 0"
"leadingZero": {"example": 01},
"unterminatedFraction": {"example": .1},
"openObject": {
"street": "7504 Taylor Drive",
"city": "New York City",
"state": "New York",
"postalCode": "11238"
]
Empty JSON file shows a warning to the user!
# Empty JSON File
- Built With
- Live Demo
- Getting started
- Prerequisites
- Setup
- Usage
- Testing
- Author
- Contributing
- Show your support
- License
- Ruby
- RSpec
You can check out the live demo here
To get a local copy up and running, follow these simple example steps.
- Install the prerequisites on your local machine
- Clone the repository to your local machine as described in the setup section
- run the enumerable.rb file using ruby in your terminal as described in the usage section
- Code Editor
- Terminal (Bash)
- Git
- Ruby
- Open your terminal and navigate to the location in which you would like to setup your copy of the project.
- Run the following command in your terminal
git clone https://github.com/joshuaivie/mv-rb_JSON-Linter/
- Ensure you're in the directory in which you've set up the project
- Run the following command replacing the relative file path with the path of the file you wish to test
bin/main.rb [./relative/file/path]
This project uses the ruby spec gem for testing.
gem install rspec && cd mv-rb_JSON-Linter && rspec
👤 Joshua Ivie
- GitHub: @joshuaivie
- Twitter: @joshuaivie_
- LinkedIn: joshuaivie
Contributions, issues, and feature requests are welcome!
Feel free to check the issues page.
Give a ⭐️ if you like this project!
This project is MIT licensed.