An open API service indexing awesome lists of open source software.

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

Awesome Lists containing this project

README

          

# Hjson, the Human JSON written in Ruby

[![Build Status](https://img.shields.io/travis/hjson/hjson-rb.svg?style=flat-square)](http://travis-ci.org/hjson/hjson-rb)
[![gem](https://img.shields.io/gem/v/hjson.svg?style=flat-square)](https://rubygems.org/gems/hjson)
[![License](https://img.shields.io/github/license/hjson/hjson-rb.svg?style=flat-square)](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\\""
}
HJSON

Hjson.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).