RABL actually can render ruby hashes and arrays easily, as attributes, just not as the root object. So, for instance, if you create an OpenStruct like this for the root object:
@my_object = OpenStruct.new
@my_object.data = {:c => {:d => 'e'}}
Then you could use this RABL template:
object @my_object
attributes :data
And that would render:
{"data": {"c":{"d":"e"}} }
Alternatively, if you want :c
to be a property of your root object, you can use "node" to create that node, and render the hash inside that node:
# -- rails controller or whatever --
@my_hash = {:c => {:d => :e}}
# -- RABL file --
object @my_hash
# Create a node with a block which receives @my_hash as an argument:
node { |my_hash|
# The hash returned from this unnamed node will be merged into the parent, so we
# just return the hash we want to be represented in the root of the response.
# RABL will render anything inside this hash as JSON (nested hashes, arrays, etc)
# Note: we could also return a new hash of specific keys and values if we didn't
# want the whole hash
my_hash
end
# renders:
{"c": {"d": "e"}}
Incidentally, this is exactly the same as just using render :json => @my_hash
in rails, so RABL is not particularly useful in this trivial case ;) But it demonstrates the mechanics anyway.