Project

aerials

0.0
No commit activity in last 3 years
No release in over 3 years
Sorted json generator. Use it for hash signing.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.6
>= 0
~> 3.1
 Project Readme

Aerials

Gem generates constant JSON. As consequence, you can MD5 it and this will remain the same.

Installation

Add this line to your application's Gemfile:

gem 'aerials'

And then execute:

$ bundle

Or install it yourself as:

$ gem install aerials

Usage

JSON generation rules:

  • No extra spaces
  • Always use double quotes for keys and array/hash values ("")
  • Always add slashes to double quotes (replace " with ")
  • Always use UTF8 (TODO)
  • Always sort by keys on each level (arrays should be sorted by values)
  • Always sort as strings

Example:

struct = {
    array: [2, '1'],
    hash: {
        'a' => '1'
    },
    a: 2,
}
Aerials.create_json struct

# will eq
# '{"a":"2","array":["1","2"],"hash":{"a":"1"}}'

You can exclude fields:

Aerials.create_json(struct, exclude: [:controller])

Or use default Rails exclusion:

Aerials.create_json_rails struct
# equals to:
Aerials.create_json struct, exclude: [:action, :controller, :key]

Contributing

  1. Fork it ( https://github.com/appelsin/aerials )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request