# Custom Code

Source: https://www.digiparser.com/docs/guides/post-processing/custom-code

Post Processing

# Custom Code

Write custom code to transform your extracted data

Copy MarkdownOpen

# [Custom Code](#custom-code)

Feedback

**Custom Code** lets you write **JavaScript code** to transform, clean, and enrich your extracted data. You can format dates, clean numbers, match values, and more. If you're not comfortable writing code, you can use **AI** to generate it for you.

## [What is custom code?](#what-is-custom-code)

Feedback

Custom code is **JavaScript code** that runs after DigiParser extracts data from your documents. It can:

Feedback

*   **Transform values** - Format dates, clean numbers, remove currency symbols
*   **Calculate fields** - Add totals, compute percentages, combine values
*   **Standardize data** - Convert text formats, trim spaces, normalize values
*   **Enrich data** - Fetch additional information from external sources (via HTTP requests)

## [Where to write code](#where-to-write-code)

Feedback

1.  Go to **Settings -> Post Processing**.
2.  Click the **Custom Code** tab.
3.  You'll see a **code editor** with sample code. Write or modify the code there.

app.digiparser.com![Post Processing Custom Code tab with code editor](https://documents.digiparser.com/docs/screenshots/2026-07-23/post-processing-custom-code-editor-clean.png?sig=3a890084dc3c083d1d5802be9ea153f040acb261e4e2bdfdf50fc78fa7a7ac3a)

## [Using AI to generate code](#using-ai-to-generate-code)

Feedback

If you're not comfortable writing code, you can use **AI** to generate it:

Feedback

1.  In the **Custom Code** tab, click **Ask AI to Write Code**.
2.  **Describe** what you want the code to do (e.g. "Remove currency symbols from all price fields and convert them to numbers").
3.  The AI generates code for you.
4.  **Review** the generated code, test it, and save if it works.

app.digiparser.com![AI code generation dialog](https://documents.digiparser.com/docs/screenshots/2026-07-23/post-processing-custom-code-ask-ai-dialog-clean.png?sig=2f8c4d9b95813b1182476816fce10305694b3004bc645b7f41788a96b843f345)

## [Testing your code](#testing-your-code)

Feedback

1.  **Select a document** from the dropdown (uses real extracted data from your parser).
2.  Click **Run** to test the code.
3.  **Compare** the **Input Data** (left) with **Output Data** (right) to see what changed.
4.  If it looks good, click **Save** to apply it to all future documents.

app.digiparser.com![Code editor with Input Data, Output Data, and Run button](https://documents.digiparser.com/docs/screenshots/2026-07-23/post-processing-custom-code-editor-clean.png?sig=3a890084dc3c083d1d5802be9ea153f040acb261e4e2bdfdf50fc78fa7a7ac3a)

## [Common examples](#common-examples)

### [Remove currency symbols](#remove-currency-symbols)

```
// Remove $ and convert to number
if (data.total) {
  data.total = parseFloat(data.total.replace(/[$,]/g, ''));
}

return data;
```

### [Format dates](#format-dates)

```
// Convert "November 8, 2024" to "2024-11-08"
if (data.invoice_date) {
  const date = new Date(data.invoice_date);
  data.invoice_date = date.toISOString().split('T')[0];
}

return data;
```

### [Clean multiple fields](#clean-multiple-fields)

```
// Clean amounts in multiple fields
if (data.subtotal) {
  data.subtotal = parseFloat(data.subtotal.replace(/[$,]/g, ''));
}
if (data.tax) {
  data.tax = parseFloat(data.tax.replace(/[$,]/g, ''));
}
if (data.total) {
  data.total = parseFloat(data.total.replace(/[$,]/g, ''));
}

return data;
```

## [Important rules](#important-rules)

Feedback

*   **You can only modify existing fields** - You cannot add new fields that don't exist in your schema
*   **Keep each field's structure** - Arrays must stay arrays, objects must stay objects, and simple values must stay simple values
*   **Return data when writing code yourself** - Ending with `return data;` makes the intended result clear
*   **Use `axios` for HTTP requests** - Available methods include `axios.get()`, `axios.post()`, `axios.put()`, and `axios.delete()`

## [Tips](#tips)

Feedback

*   **Start with AI** - Use "Ask AI to Write Code" if you're not sure how to write the code
*   **Test first** - Always test on a sample document before saving
*   **Keep it simple** - Start with basic transformations, then add more complex logic
*   **Use examples** - The code editor includes example code you can modify

## [Next steps](#next-steps)

Feedback

*   [Lookups](/docs/guides/post-processing/lookup-tables) - Match values using CSV files or parser data
*   [Clean and Format Data](/docs/guides/post-processing/data-transformations) - Use Ask AI for common formatting tasks

How is this guide?

GoodBad

[

Lookups

Match and enrich extracted data with CSV files or parser data

](/docs/guides/post-processing/lookup-tables)[

Workflows and Recipes

Complete common DigiParser tasks from start to finish

](/docs/guides/workflows)