class Jbuilder
def key_format!(*args)
{ "_first_name": "David" }
json.first_name "David"
json.key_format! ->(key){ "_" + key }
Lambdas can also be used.
{ "firstName": "David" }
json.first_name "David"
json.key_format! camelize: :lower
You can pass parameters to the method using a hash pair.
{ "AUTHOR": { "NAME": "David", "AGE": 32 } }
end
json.age 32
json.name "David"
json.author do
json.key_format! :upcase
Example:
the key. You can also pass in lambdas for more complex transformations.
will cause that function to be called on the key. So :upcase will upper case
Specifies formatting to be applied to the key. Passing in a name of a function
def key_format!(*args) @key_formatter = KeyFormatter.new(*args) end