PARSER GUIDES
Custom Code
Post Processing
Write custom code to transform your extracted data
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?
Custom code is JavaScript code that runs after PARSER extracts data from your documents. It can:
- 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
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.
guide-guides-post-processing-custom-code-01-post-processing-custom-code-editor-clean.webpRequired PARSER view: Post Processing Custom Code tab with code editorFuture alt text: Post Processing Custom Code tab with code editorUsing AI to generate code
If you're not comfortable writing code, you can use AI to generate it:
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.
guide-guides-post-processing-custom-code-02-post-processing-custom-code-ask-ai-dialog-clean.webpRequired PARSER view: AI code generation dialogFuture alt text: AI code generation dialogTesting your code
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.
guide-guides-post-processing-custom-code-03-post-processing-custom-code-editor-clean.webpRequired PARSER view: Code editor with Input Data, Output Data, and Run buttonFuture alt text: Code editor with Input Data, Output Data, and Run buttonCommon examples
Remove currency symbols
// Remove $ and convert to number
if (data.total) {
data.total = parseFloat(data.total.replace(/[$,]/g, ''));
}
return data;
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 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
- 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
axiosfor HTTP requests - Available methods includeaxios.get(),axios.post(),axios.put(), andaxios.delete()
Tips
- 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
- Lookups - Match values using CSV files or parser data
- Clean and Format Data - Use Ask AI for common formatting tasks