Skip to content

WinterCore/jsonerino

Repository files navigation

JSONERINO

JSONERINO is a lightweight json parser written in ruby. with no dependencies. It also contains a command line tool for validating json files (check below).

Usage

First of all you need to add the following to your Gemfile

gem 'jsonerino'

Then you need to run bundle install.

After that you can use it to parse json by calling the parse method

require 'jsonerino'

p Jsonerino::parse('nil') == nil # true

output = Jsonerino::parse('[{"name" : "Alex", "age" : 15 }]')

p output == [{"name" => "Alex","age" => 15}] # true

Calling the parse method will convert the json string to it's corresponding ruby representation.

Run on Repl.it

Using the included json validator

CLI DEMO

  • Run gem install jsonerino
  • Run jsonerino <file|directory> If no filename is provided. jsonerino will try to parse all the JSON files that are in your current working directory.

Invalid JSON Examples

{ "foo: true }

Will throw "End of data reached while reading JSON contents" error. Because the parser will interpret everything after the first double quotes character as a string and it continues reading until it finds a closing double quotes. But in this case it doesn't which is why an error is thrown.

{ "hey": foo }

Will throw "Unexpected token foo". Because foo is an unkown identifier. The allowed identifiers in JSON are true, false, and null. And in this case the error can be fixed by wrapping it in a string.

Built with

  • Ruby

Development Commands

  • Run tests bundle exec rspec
  • Run rubocop (code linter) bundle exec rubocop

Note: Make sure to run bundle install in the project's directory before trying to run the previous commands.

Authors

👤 WinterCore

🤝 Contributing

Contributions, issues and feature requests are welcome! Start by:

  • Forking the project
  • Cloning the project to your local machine
  • cd into the project directory
  • Run git checkout -b your-branch-name
  • Make your contributions
  • Push your branch up to your forked repository
  • Open a Pull Request with a detailed description to the development branch of the original project for a review

Show your support

Give a ⭐️ if you like this project!

About

Another JSON parser written from scratch in Ruby

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published