Project

rb_json5

0.0
No release in over 3 years
Low commit activity in last 3 years
JSON5 parser for Ruby
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 3.5.0
~> 3.9.0
~> 0.88.0
~> 0.18.0
~> 0.9.0

Runtime

~> 2.0
 Project Readme

Gem Version CI Maintainability codecov Inline docs

RbJSON5

JSON5 parser for Ruby

Installation

Add this line to your application's Gemfile:

gem 'rb_json5'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install rb_json5

Usage

Use RbJSON5.parse method to parse JSON5 string. You can convert property names into Symbol by setting symbolize_names optional argument to true.

require 'rb_json5'

# https://github.com/json5/json5#short-example
json5 = <<~'JSON5'
{
   // comments
   unquoted: 'and you can quote me on that',
   singleQuotes: 'I can use "double quotes" here',
   lineBreaks: "Look, Mom! \
 No \\n's!",
   hexadecimal: 0xdecaf,
   leadingDecimalPoint: .8675309, andTrailing: 8675309.,
   positiveSign: +1,
   trailingComma: 'in objects', andIn: ['arrays',],
   "backwardsCompatible": "with JSON",
 }
JSON5

RbJSON5.parse(json5)
  # =>
  # {
  #   "unquoted"=>"and you can quote me on that",
  #   "singleQuotes"=>"I can use \"double quotes\" here",
  #   "lineBreaks"=>"Look, Mom! No \\n's!",
  #   "hexadecimal"=>912559,
  #   "leadingDecimalPoint"=>0.8675309,
  #   "andTrailing"=>8675309.0,
  #   "positiveSign"=>1,
  #   "trailingComma"=>"in objects",
  #   "andIn"=>["arrays"],
  #   "backwardsCompatible"=>"with JSON"
  # }
RbJSON5.parse(json5, symbolize_names: true)
  # =>
  # {
  #   :unquoted=>"and you can quote me on that",
  #   :singleQuotes=>"I can use \"double quotes\" here",
  #   :lineBreaks=>"Look, Mom! No \\n's!",
  #   :hexadecimal=>912559,
  #   :leadingDecimalPoint=>0.8675309,
  #   :andTrailing=>8675309.0,
  #   :positiveSign=>1,
  #   :trailingComma=>"in objects",
  #   :andIn=>["arrays"],
  #   :backwardsCompatible=>"with JSON"
  # }

Contributing & Contact

Bug reports, feature requests, pull requests and questions are welcome! You can use following methods:

Note

Test-suite and JSON5 code snippets for RSpec examples are originaly from:

Copyright & License

Copyright © 2020 Taichi Ishitani. RbJSON5 is licensed under MIT License, see LICENSE for further details.

Code of Conduct

Everyone interacting in the RbJson5 project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.