> ## Documentation Index
> Fetch the complete documentation index at: https://docs.incident.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Extracting JSON alert data

When configuring alerts you can choose to extract specific fields you care about from the JSON payload of your alert.

You can manage this by navigating to [Alerts > Sources](https://app.incident.io/~/on-call/alert-routes/sources) and editing the alert source you wish to extract information from.

While editing the alert, click on the icon in the attributes section.

<img src="https://mintcdn.com/incidentio-18bb4170/8YOLrDxhRXqwWcel/images/help-centre/extracting-json-alert-data/screenshot-1.png?fit=max&auto=format&n=8YOLrDxhRXqwWcel&q=85&s=8c8ec4ba4f170d984f8ff673f24bb3c7" alt="The Attributes section of an alert source, with a Suggested attribute card and a Review button" width="1240" height="532" data-path="images/help-centre/extracting-json-alert-data/screenshot-1.png" />

Once you are ready to add a new attribute, you can choose to add attributes through the use of AI, we will parse through the payload and suggest attributes that are commonly seen and can be linked to a catalog type.

Or you can choose to link an existing attribute or start from scratch by parsing the payload directly.

<img src="https://mintcdn.com/incidentio-18bb4170/8YOLrDxhRXqwWcel/images/help-centre/extracting-json-alert-data/screenshot-2.png?fit=max&auto=format&n=8YOLrDxhRXqwWcel&q=85&s=5d3e9a022046e3317fbb2e30f6016545" alt="Found suggested attributes, offering Accept or Skip for a parsed Team attribute" width="1244" height="1100" data-path="images/help-centre/extracting-json-alert-data/screenshot-2.png" />

***

## Extracting fields from JSON

You can see the alert payload for all the alerts you've received.

Write your query in the step **Then extract fields from JSON**. By default, use `$` to reference the payload, then access fields like `$.field`, or `$.items[0].name`.

For logic the `$` syntax can't express, such as filtering or reshaping an array, use the `</>` toggle on the field to switch to JavaScript.

<Info>
  Expressions here can use synchronous JavaScript up to ES2023, including arrow functions, template literals, destructuring, optional chaining (`?.`), nullish coalescing (`??`), object spread (`{ ...obj }`) and newer methods such as `Object.hasOwn`, `Object.groupBy` and `toSorted`.

  `async` functions and Promises, generators, `Symbol`, `Map` and `Set` aren't supported.
</Info>

<img src="https://mintcdn.com/incidentio-18bb4170/XsSsM18yW6o4p-bZ/images/help-centre/extracting-json-alert-data/screenshot-3.png?fit=max&auto=format&n=XsSsM18yW6o4p-bZ&q=85&s=7d07bf9b5737f14ce211027be8fb1d9c" alt="The Then extract fields from JSON step with the query $.issue.severity and a preview of MEDIUM" width="1216" height="1050" data-path="images/help-centre/extracting-json-alert-data/screenshot-3.png" />

## Options to extract values from the payload

## 1. Extract a simple field

If you click on any field displayed in the payload, you'll automatically see this value extracted.

For example, to extract the `service` field from your metadata, use

```text theme={null}
$.metadata.service
```

This will dynamically fetch whichever value is in the `service` field and apply it to your alert.

## 2. Map array fields

To map an array field, switch the field to JavaScript with the `</>` toggle.

In our JSON payload, our tags field has the following format:

```javascript theme={null}
tags: ['feature:api', 'feature:payments', 'service:api'];
```

To filter only certain values from our tags, we can use JavaScript filtering:

```javascript theme={null}
$.metadata.tags.filter((tag) => tag.startsWith("feature:"))

// This returns the following
feature:api, feature:payments
```

To map your array, you can also use standard JavaScript functions:

```javascript theme={null}
$.metadata.tags.map((tag) => tag.split(':')[1]);

// This returns the following
(api, payments);
```

To ensure that your output preserves all values from your array, select *Result is an array.*

Otherwise, your result will just select the first value of your array.

<img src="https://mintcdn.com/incidentio-18bb4170/8YOLrDxhRXqwWcel/images/help-centre/extracting-json-alert-data/screenshot-4.png?fit=max&auto=format&n=8YOLrDxhRXqwWcel&q=85&s=8404680ce00a73f4c740ca5082006e5d" alt="The Choose what the result should be parsed into step, set to String with Result is an array ticked" width="886" height="280" data-path="images/help-centre/extracting-json-alert-data/screenshot-4.png" />

## 3. Write a custom JavaScript snippet

JavaScript here supports ES2023, so you can write custom code that will allow you to get creative on how you extract values from the payload. If you're a bit rusty with JavaScript then it can also be well worth asking an AI coding assistant to help write any given expression - a prompt of " *write a synchronous JavaScript expression to do x* " usually works quite well
