Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize JSON Response #454

Open
w3villa-amit opened this issue Feb 13, 2020 · 3 comments
Open

Customize JSON Response #454

w3villa-amit opened this issue Feb 13, 2020 · 3 comments

Comments

@w3villa-amit
Copy link

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
Copy link

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

@w3villa-amit
Copy link
Author

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

@nischay-dhiman
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants