> For the complete documentation index, see [llms.txt](https://docs.jetadmin.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.jetadmin.io/user-guide/sql-queries-and-api-requests/api-builder/transform-api-responses.md).

# Transform API responses

Select nested records and transform API response fields.

Transform a response when its structure does not match the fields your component needs. Test the original request first, then compare the transformed output.

## Example response

This guide uses the public [DummyJSON Users API](https://dummyjson.com/docs/users). With the base URL `https://dummyjson.com`, send a GET request to `/users?limit=2&select=id,firstName,lastName`.

The response contains a `users` array alongside pagination metadata. The records used below are:

```json
{
  "users": [
    {"id": 1, "firstName": "Emily", "lastName": "Johnson"},
    {"id": 2, "firstName": "Michael", "lastName": "Williams"}
  ]
}
```

<figure><img src="https://3448227606-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LQ08RFAKZvFADEiXKFy%2Fuploads%2FcnNjFPfTyyje3bgNnJBw%2FS26a-api-original-response.jpg?alt=media" alt="Original API response with users, total, skip, and limit"><figcaption><p>Before extracting records, the users array appears inside the response object.</p></figcaption></figure>

## Select the response root

1. Open **Transform**.
2. In the preview, open **NEST** on the **users** column and choose **Nested data as result**.
3. Check that the response root shows **Top Level → users** and that the preview contains two rows.

<figure><img src="https://3448227606-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LQ08RFAKZvFADEiXKFy%2Fuploads%2F4tKnKGlBJik1N6vl3C60%2FS26b-api-response-root.jpg?alt=media" alt="Users response root and two individual user records"><figcaption><p>Selecting users exposes id, firstName, and lastName as columns.</p></figcaption></figure>

{% @arcade/embed url="<https://app.arcade.software/share/CXNncl0iKUKIJ3SaRnyU>" flowId="CXNncl0iKUKIJ3SaRnyU" %}

## Transform fields with JavaScript

As an alternative to selecting the nested array, use a JavaScript transform on the original response object. The variable `data` contains the response.

1. Open **Transform → JavaScript transform**.
2. Enter this code:

```javascript
return data.users.map(user => ({
  id: user.id,
  name: user.firstName + " " + user.lastName
}));
```

3. Run **Test Request** and inspect the output:

```json
[
  {"id": 1, "name": "Emily Johnson"},
  {"id": 2, "name": "Michael Williams"}
]
```

<figure><img src="https://3448227606-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LQ08RFAKZvFADEiXKFy%2Fuploads%2FHcn7LAG1k16zN7AvFBUz%2FS27-api-javascript-transform.jpg?alt=media" alt="JavaScript mapping and successful preview with id and name"><figcaption><p>The transform combines firstName and lastName into name while preserving each ID.</p></figcaption></figure>

4. Test an empty list: `{"users":[]}` should return `[]`.
5. Save after the preview matches the fields your component needs.

This code expects the original object with a `users` array. If you already selected that array as the root, inspect the value passed to the transformation and adjust the code accordingly.

The existing walkthrough below demonstrates another field-mapping example.

{% @arcade/embed url="<https://app.arcade.software/share/Ee03QJrhnsvigKOhEqk7>" flowId="Ee03QJrhnsvigKOhEqk7" %}

If the API returns an error or a different shape, resolve that before mapping fields. See [Handle API errors](/user-guide/sql-queries-and-api-requests/api-builder/error-handling.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.jetadmin.io/user-guide/sql-queries-and-api-requests/api-builder/transform-api-responses.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
