Last active
October 18, 2018 09:08
-
-
Save kokigit/ffc9d0d334e2d3140cb1cf51bbe5a680 to your computer and use it in GitHub Desktop.
to print rails(ruby) objects as indented(pretty json) json output add this function to ~/.irbrc file(if not exist create one). then it will be loaded with irb or rails console
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pp(obj) | |
puts JSON.pretty_generate({ "#{obj.class.name.underscore}" => obj }.as_json) | |
end | |
# console command | |
#pp Company.first | |
#and the output | |
# { | |
# "company": { | |
# "id": 1, | |
# "name": "John Corporation", | |
# "email": "[email protected]", | |
# "created_at": "2018-02-27 09:44:12 +0530", | |
# "updated_at": "2018-03-12 05:46:56 +0530", | |
# "hash_key": "GyClIpdDsCvIBQ", | |
# "logo": null, | |
# "logo_url": null, | |
# "address": null, | |
# "phone": null, | |
# "country": "LKA", | |
# "timezone": "Sri Jayawardenepura", | |
# "app_logo": null, | |
# "verification": false, | |
# "ses_access": "AKIATRYTHISIDIOTFZ4LJA", | |
# "ses_secret": "FCnAKQwVONEIDIOTWILLTRYTHISh570GSJ5kS", | |
# "ses_server": "email.us-east-1.amazonaws.com", | |
# "authentication_token": "kGL4nDEVGhKg" | |
# } | |
# } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment