The default way to output JSON in rails is some thing like:
Code:
render :json => friends.to_json(:only => [:username, :avatar_file_name, :id ])
Output
{"friends" : [{"user": {"avatar_file_name": "image1.jpg", "username": "user1", "id": 1}}, {"user": {"avatar_file_name": "image2.jpg", "username": "user2", "id": 2}}, {"user": {"avatar_file_name": "image3.jpg", "username": "user3", "id": 3}} ]}
But i want something like:
{"friends" : {"user": [ {"avatar_file_name": "image1.jpg", "username": "user1", "id": 1}, {"avatar_file_name": "image2.jpg", "username": "user2", "id": 2}, {"avatar_file_name": "image3.jpg", "username": "user3", "id": 3} ]} }
The class is specified by the array name.
Last.fm also uses this syntax see Last.fm 'API-user.getfriends'