DEV Community

Nikola Mitrovic
Nikola Mitrovic

Posted on

Parsing Incoming Emails into Structured JSON with Node and AI

Email is still one of the most common “integration APIs” in business and that's why I made https://www.parseforce.io

Invoices. Shipping notices. Order confirmations. Supplier updates.

And in many cases… email is the only integration point you get.

The problem?

Emails are messy.

  • Layout changes
  • Forwarded threads
  • HTML formatting
  • Different senders, different structures
  • Slight wording tweaks that break everything

Yet inside those emails is structured data you actually need.


The Regex Trap

Most teams start with regex or template-based parsing.

It works at first:

const match = emailBody.match(/Total:\s*\$([0-9,\.]+)/);
Enter fullscreen mode Exit fullscreen mode

Then one day:

“Total” becomes “Amount Due”

The currency moves

The supplier updates their template

Someone forwards the email

And your parser breaks.

You’re now maintaining parsing logic instead of building product.

A Different Approach

Instead of matching patterns, define the schema you want:

{
  "invoiceNumber": "string",
  "items": [],
  "total": "number",
  "currency": "string"
}
Enter fullscreen mode Exit fullscreen mode

Then extract structured JSON that conforms to that schema.

Your workflow becomes:

Incoming email
↓
Extract structured data
↓
Validate
↓
Send to webhook
Enter fullscreen mode Exit fullscreen mode

Now your backend only deals with clean JSON.

Making Email Feel Like Webhooks

The goal is simple:

Turn this:

email → chaos

Into this:

email → structured JSON → webhook

So your systems can treat email like any other API input.

A Practical Note

If you go this route:

Always store raw emails

Validate extracted fields

Handle low-confidence cases

Expect edge cases

Email isn’t going away.
But it doesn’t have to be painful.
More details about the tool.

Top comments (0)