We are returning the following JSON from a ruby code:
{
"label":"CPU-7",
"data":[[50,45,38,34]],
"settings":{
"seriesDefaults":{
"renderer":"$.jqplot.BarRenderer"
},
"axes":{
"xaxis":{
"renderer":"$.jqplot.CategoryAxisRenderer",
"ticks":[50,45,38,34]
}
}
}
}
However, “$.jqplot.BarRenderer” is an object and we don’t want it to be returned as string, is there a way to do this?
This doesn’t directly answer your question but gives an alternative. See my note below though if you absolutely must do what you’re wanting
You probably don’t want your ruby code to know anything about your javascript objects. Rather you can maintain some sort of
typestructure such that if you returned data is of typebarChartyou can reference it that way. SOmething like:Then if you returned:
You can use
Again, I’d avoid having your ruby know anything about your javascript objects or how you’re actually rendering the data. Ruby should just provide the data, javascript chooses what to do with it.
note
to get an actual object from your json string, just do