No commit activity in last 3 years
No release in over 3 years
Use custom names in JSON keys and your custom logic in JSON values
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
 Project Readme

#JsonSerializable In my projects I have found the basic as_json method that you get from Rails to be quite limiting. For example, as_json takes :methods, but the hash key can only be the method's name. Similar restriction applies to the :only option. So, I am extending this method in JsonSerializable so that you can customize your JSON output with a simple declarative syntax.

Build Status

Build Status

##In you Gemfile:

gem :json_serializable

##Or install directly:

gem install json_serializable

##In your model:

class Content
  include JsonSerializable

  json_serializable [:name, :description], private: lambda {|content| content.secret_data.upcase}, :street => :address

  def street
    "#{street_number} #{street_name}"
  end

end

##If your model has the following data:

calgaryNews = Content.new(name: 'Sunny', description: 'Awesome sunny and bright day', secret_data: 'ggh98',
                          street_number: 2301, street_number: 'Varsity DR NW')

##JsonSerializable will produce the following Hash for your json:

calgaryNews.as_json
#==>
{
  name: 'Sunny', description: 'Awesome sunny and bright day', private: 'GGH98',
                            address: "2301 Varsity DR NW'
}

##Feedback

Use the Issues page or knock me at @smsohan if its quick!

##License

Released under DTFYW (Do the F* You Want) License.