Data Transformation

There are a number of reasons why you may want (or need) to transform your data response using a Transformer. For example, you may want to:

  • Transform the response into an array of objects or a single object. Most components in Internal require your Function to return an array of objects or a single object in order to display the results of your HTTP request.
  • Transform the response to return a specific set of fields. In many cases, your request may return too many objects, objects that are deeply nested, or otherwise in a format that doesn’t work for the tools you want to build.

Transformers can be written using JavaScript expressions. Let’s take a look at a a couple examples below:

📘

Note:

Transformers are limited to a MAX of 2048 characters.

Example 1:

Below is the response we’re starting with. It’s a single object with a lot of information being returned.

To only return the data within “list” as an array of objects, we wrote this simple Transformer:

And here’s the new Transformed Response:

Example 2:

Below is the response we’re starting with. It’s an array of objects, but the object is nested.

Here’s the transformer we’ve written to pull out specific fields we want the request to return:

And here’s the new Transformed Response: