I’m generating json from a Rails app, and am filtering fields using the format.json and to_json methods. It is working fine, except the json does not have an object name. This is the Rails code:
format.json { render :json => @text.to_json(:only =>[:id,:language,:text_name,:text_type,:text_content])}
And a part of the json output:
[{"id":5,"language":"TR","text_name":"2.01 AY\u015eE'DEN MEKTUP","text_type":null},{"id":6,"language":"TR","text_name":"2.02 Ruya","text_type":null},{"id":7.... etc
Where I was thinking I would receive something indicating the name of the object (eg: “texts”). More along the lines of:
{"texts:"[{"id":5,"language":"TR","text_name":"2.01 AY\u015eE'DEN MEKTUP","text_type":null},{"id":6,"language":"TR","text_name":"2.02 Ruya","text_type":null},{"id":7.... etc
The following render line will produce the result you’re looking for: