Parse a DMARC record

Split a published DMARC TXT value into its tags.

JavaScript Version 1.0.0 · MIT · by Oveyon · .md

parse-a-dmarc-record.js
function parseDmarc(record) { return Object.fromEntries(record.split(';').map(tag => tag.trim()).filter(Boolean).map(tag => [tag.slice(0, tag.indexOf('=')).trim().toLowerCase(), tag.slice(tag.indexOf('=') + 1).trim()])); }

Input & expected output

Input

"v=DMARC1; p=quarantine; rua=mailto:[email protected]; adkim=s"

Expected output

{
  "v": "DMARC1",
  "p": "quarantine",
  "rua": "mailto:[email protected]",
  "adkim": "s"
}

The edge case

Input

"v=DMARC1;p=reject;"

Expected output

{
  "v": "DMARC1",
  "p": "reject"
}

Know the limits

  • Tag names are lowercased; values are kept as published. Unknown tags are returned, not validated.
  • The lab requires v=DMARC1 as the first tag and = in every tag, as receivers discard other records (RFC 7489). Check that p is present: it is the policy receivers apply.

The function above is the implementation used by the lab. The lab validates JSON types and caps size before execution; include equivalent validation when accepting untrusted input in your application.

Source & maintenance

Written by Oveyon for this edition of 1loc.dev; it is not part of the original collection. Copyright (c) 2026 Oveyon. MIT licensed.

The function above is the implementation the lab runs and the tests exercise. Read the license.

Local fixture scope · Node.js 22.23.2 · reviewed October 28, 2026. No external service is required.

Keep exploring

Type two or more characters. Try “duplicate”, “webhook” or “retry”.