I am new to JSON and Ruby on Rails (ruby 1.9.3, rails 3.2.13) and I am trying to add an array name/identifier to a JSON object that contains an already defined array.
My ruby on rails code in a controller is:
metricTypes = MetricType.all
respond_to do |format|
format.json {render :json => metricTypes}
end
What gets spit out is:
[
{
"id":1,
"name":"foo"
},
{
"id":2,
"name":"bar"
}
]
but what I would like to get is:
{
metrics: [
{
"id":1,
"name":"foo"
},
{
"id":2,
"name":"bar"
}
]
}
How can I modify the JSON object to include the array name/identifier? I may need to include other arrays other than "metrics" in the same json object in the future, which is why I am trying to do this. Thanks!