Netflix / fast_jsonapi

No Longer Maintained - A lightning fast JSON:API serializer for Ruby Objects.
Apache License 2.0
5.07k stars 425 forks source link

Customize JSON Response #454

Open w3villa-amit opened 4 years ago

w3villa-amit commented 4 years ago

Hello Everyone please help me I am using the Active model serializer in my project as i saw the the fast json API serializer is fast from the Active model serializer but i am stuck during customisation of the json response Here is my previous JSON -: {id: 3129, status_name: "To-do", name: "hkjhkSASFSFSDAFASDF", owner_id: 0, status_id: 42, points: null,…} id: 3129 status_name: "To-do" name: "hkjhkSASFSFSDAFASDF" owner_id: 0 status_id: 42 points: null date: "Tuesday, 04 Feb 2020" project_story_id: 141 index: 0 seen: false tags: [] owner: null categories: [] story_categories: []

And here is the Fast Json Api response -: data: [{id: "3129", type: "story_light",…}, {id: "2987", type: "story_light",…},…] 0: {id: "3129", type: "story_light",…} id: "3129" type: "story_light" attributes: {id: 3129, status_name: "To-do", name: "hkjhkSASFSFSDAFASDF", owner_id: 0, status_id: 42, points: null,…} id: 3129 status_name: "To-do" name: "hkjhkSASFSFSDAFASDF" owner_id: 0 status_id: 42 points: null date: "Tuesday, 04 Feb 2020" project_story_id: 141 index: 0 seen: false relationships: {tags: {data: []}, owner: {data: {id: "0", type: "owner"}}, categories: {data: []},…} tags: {data: []} owner: {data: {id: "0", type: "owner"}} categories: {data: []} story_categories: {data: []}

Please Help!

rajdeepbhatia commented 4 years ago

It strictly follows JSON:API formatting. https://jsonapi.org/

w3villa-amit commented 4 years ago

Is there any way to remove the attributes and relationship key and transform them into a single merged hash.

nischay-dhiman commented 4 years ago

@w3villa-amit You can try using .as_json['data'].map{ |v| v['attributes'] } Or using a custom method over it to generate expected response.

However, use of this gem encourages the response of only the latest JSON:API formatting and I suggest you make changes on the client-side to consume such response.