https://github.com/hjson/hjson-rb
Hjson for Ruby
https://github.com/hjson/hjson-rb
hjson maintainer-wanted ruby
Last synced: 6 months ago
JSON representation
Hjson for Ruby
- Host: GitHub
- URL: https://github.com/hjson/hjson-rb
- Owner: hjson
- License: mit
- Created: 2016-07-27T11:48:12.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-06-27T22:44:25.000Z (over 6 years ago)
- Last Synced: 2025-04-03T11:42:13.970Z (6 months ago)
- Topics: hjson, maintainer-wanted, ruby
- Language: Ruby
- Homepage: https://hjson.github.io/
- Size: 30.3 KB
- Stars: 24
- Watchers: 6
- Forks: 6
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Hjson, the Human JSON written in Ruby
[](http://travis-ci.org/hjson/hjson-rb)
[](https://rubygems.org/gems/hjson)
[](https://github.com/hjson/hjson-rb/blob/master/LICENSE.txt)A configuration file format for humans. Relaxed syntax, fewer mistakes, more comments for Ruby.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'hjson'
```And then execute:
$ bundle
Or install it yourself as:
$ gem install hjson
## Usage
You can use Hjson as `JSON.parse` of standard library.
Please check it out.
```ruby
require 'hjson'hjson = < {"rate"=>1000}
```### Quotes
You don't need to quote keyname.
```ruby
require 'hjson'hjson =< {"key"=>"value"}
```### Commas
You can forget the comma at the end, Hjson recognizes the end automatically.
```ruby
require 'hjson'hjson =< {"one"=>1, "two"=>2, "three"=>4}
```### Quoteless
Hjson makes quotes for strings optional as well.
```ruby
require 'hjson'hjson =< {"text"=>"look ma, no quotes!"}
```### Escapes
You don't need to escape in unquoted strings.
```ruby
require 'hjson'hjson = <
# inside quotes, escapes work
# just like in JSON
escape: "\\\\ \n \t\\""
}
HJSONHjson.parse(hjson)
",
#=> {"regex"=>"^d*.{0,1}d+$",
"inject"=>"
"escape"=>"\\ \n \t\""}
```### Multiline
Hjson allows you to use `'''` for writing multiline strings.
```ruby
require 'hjson'hjson =< {"haiku"=>"JSON I love you.\nBut strangled is my data.\nThis, so much better."}
```### Braces
You can omit the braces for the root object.
```ruby
require 'hjson'hjson =< {"joke"=>"My backslash escaped!"}
```## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/namusyaka/hjson. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).