menu

JavaScript

A community to get help with JavaScript, find jobs, outsource and much more!

Channels
# All channels
view-forward
# General
view-forward
# Jobs
view-forward
# Node.js
view-forward
# React
view-forward
# Snippets
view-forward
# Vanilla
view-forward
# Vue.js
view-forward
Team

Handling transformations between api response and accepted format?

October 17, 2019 at 8:51pm

Handling transformations between api response and accepted format?

October 17, 2019 at 8:51pm
Recommend way to create maps to transform api responses into the proper format?
I have api responses that are just barely off from what I need. Namely some key names. I just need to map them to the accepted key names. For instance, this comes in from the api:
{
"id": "a48b4524-ea0e-11e9-a57f-acde48001122",
"account_id": "80885644-ea0e-11e9-a57f-acde48001122",
"custom_id": "2",
"type": "email_domain",
"label": "qlik.com",
"fields": [],
"tags": null,
"created_at": "2019-10-10T17:20:12.737003",
"updated_at": "2019-10-16T18:37:40.814512",
"deleted_at": null,
"created_by": "fbf10280-80a7-4731-afb3-6658276f6143",
"updated_by": "fbf10280-80a7-4731-afb3-6658276f6143",
"deleted_by": null
}
… and I need to transform it to this:
{
id: 'a48b4524-ea0e-11e9-a57f-acde48001122',
type: 'email_domain',
detail: 'facebook, @axe_financial_official', // « key name was “label”
created_at: '2019-10-10T17:20:12.737003',
tags: null,
}
I know how to map through and make the changes. What I would LOVE is if I could just have the approved schema as an object or something, and when run against the api response it would handle the transformation.
Is there a package around that does this?

October 17, 2019 at 10:30pm

November 25, 2019 at 4:22pm
graphql could be quite helpful for such cases? https://graphql.org/
Edited
  • reply
  • like