Transform Airtable data into simplified object structure

I need help converting a complex Airtable response into a cleaner format. Right now I have this messy data structure:

[
  {
    "_table": {
      "_base": {
        "_airtable": {},
        "_id": "appXYZ123ABC456"
      },
      "id": null,
      "name": "EventsTable"
    },
    "id": "recABC123XYZ789",
    "_rawJson": {
      "id": "recABC123XYZ789",
      "createdTime": "2022-06-15T10:30:15.000Z",
      "fields": {
        "Title": "Workshop Session 1",
        "UniqueID": "abc123def456ghi789"
      }
    },
    "fields": {
      "Title": "Workshop Session 1",
      "UniqueID": "abc123def456ghi789"
    }
  },
  {
    "_table": {
      "_base": {
        "_airtable": {},
        "_id": "appXYZ123ABC456"
      },
      "id": null,
      "name": "EventsTable"
    },
    "id": "recDEF456UVW012",
    "_rawJson": {
      "id": "recDEF456UVW012",
      "createdTime": "2022-06-16T14:20:30.000Z",
      "fields": {
        "Title": "Training Module B",
        "UniqueID": "xyz789abc012def345"
      }
    },
    "fields": {
      "Title": "Training Module B",
      "UniqueID": "xyz789abc012def345"
    }
  }
]

But what I actually want is just the clean version like this:

[
  {
    "Title": "Workshop Session 1",
    "UniqueID": "abc123def456ghi789"
  },
  {
    "Title": "Training Module B",
    "UniqueID": "xyz789abc012def345"
  }
]

Basically I want to extract only the fields property from each item and ignore all the metadata stuff. I think I should use the map function but I’m not sure how to handle nested objects like this.

I destructure right in the map function with Airtable responses. const result = data.map(({ fields }) => fields) works great. Watch out though - Airtable sometimes returns records where field values are undefined or completely missing. I add basic validation when I’m expecting specific properties. You can also use optional chaining like data.map(item => item.fields || {}) to prevent crashes if the structure changes. The nested metadata is annoying but it’s consistent across their API, so cleanup’s pretty straightforward once you know the pattern.

Had the exact same problem pulling Airtable data for a dashboard last year. Their API dumps so much unnecessary metadata.

Laura’s map approach works perfectly. Here’s what I used:

const cleanData = airtableResponse.map(record => record.fields);

Each record has a fields property with your actual data. Map just pulls that out into a clean array.

Want to be safer? Add a filter for missing fields:

const cleanData = airtableResponse
  .filter(record => record.fields)
  .map(record => record.fields);

Learned this after empty fields killed my entire pipeline. Worth the extra line.

yep, just use data.map(item => item.fields) and you’ll get exactly what you need! gives you a clean array with just the fields, no extra stuff.

You can also transform fields during mapping if needed. I’ve hit issues where Airtable field names had spaces or special characters that broke my frontend components. Something like data.map(item => ({ title: item.fields.Title, uniqueId: item.fields.UniqueID })) lets you rename properties while extracting. Also helpful to grab the record ID for later updates - data.map(item => ({ id: item.id, ...item.fields })) keeps the Airtable record ID with your clean field data. The spread operator keeps it clean and you’ve got the reference back to Airtable for record modifications.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.