Parse an X12 file in Node.js

Load the library, license the process, set the model map, then parse. This reads an 837P claim to JSON and validates it.
const fs = require("fs");
const ef = require("edifabric-x12");

const serial = "YOUR_SERIAL_KEY";   // or the demo key bd96a836feca45cb91c86ee65d281f52
ef.loadLibrary();
ef.ensureToken(serial, 3600);
ef.setMap(JSON.stringify({ default: serial, maps: {} }));

const edi = fs.readFileSync("837P_Claim.txt");
const { output, offset } = ef.parse(edi, ef.ParseMode.JSON_VALIDATE);
const transactions = output.slice(0, offset);
const report = JSON.parse(output.slice(offset));
console.log(report.errors_count);

Validate and generate a 999

Mode 3 validates, here at HIPAA SNIP level 4, and returns the acknowledgment with the report.

const config = JSON.stringify({
    validate: { snip_level: 4, max_errors: 0 },
    ack: { gen997: false, supress_ta1: false },
});
const { output, offset } = ef.parse(edi, ef.ParseMode.JSON_VALIDATE_ACK, config);
const report = JSON.parse(output.slice(offset));
console.log(report.errors_count, report.ack);   // the 999 as X12

Build X12 from JSON

Change the JSON, or create it from your own data, and build the X12 file.

const ediText = ef.build(transactions, "\r\n");

The JSON property names come from each transaction's model. See them in the EDI spec library, or in the transaction guides below. The full API, configuration and error codes are in the Node.js bindings on GitHub and the ediFabric Native docs.

What the Node.js X12 parser does

X12 to JSON and back

Parse an interchange to JSON with readable property names, change it in Node.js, and build valid X12 again with the right delimiters and trailers.

HIPAA validation

Validate up to HIPAA SNIP level 4: codes, lengths, required segments, loops and situational rules, with the segment each error is in.

999, 997 and TA1

Generate the acknowledgment your trading partner expects in the same call that validates the file.

Large files

Split an interchange into transaction sets and merge them back with split and merge functions, without loading the whole file.

Runs in your process

One native library, bundled in the npm package. No runtime, no service to call, and EDI files and PHI stay on your servers.

Custom specs

Use the standard models from the EDI spec library, or a partner-specific model built in the EDI Spec Builder.

X12 and HIPAA transaction guides

Each guide has a sample file, its JSON, and parse and build code for Node.js. Any transaction in the EDI spec library works the same way.

Healthcare (HIPAA 5010)

X12 837PHealth care claim: professional
X12 837IHealth care claim: institutional
X12 837DHealth care claim: dental
X12 835Claim payment/advice
X12 834Benefit enrollment and maintenance
X12 270Eligibility inquiry
X12 271Eligibility response
X12 276Claim status request
X12 277Claim status response
X12 277CAClaim acknowledgment
X12 278Services review
X12 820Premium payment

Supply chain and logistics

X12 850Purchase order
X12 855Purchase order acknowledgment
X12 856Ship notice/manifest
X12 810Invoice
X12 832Price/sales catalog
X12 824Application advice
X12 861Receiving advice
X12 945Warehouse shipping advice
X12 210Motor carrier freight invoice
X12 214Shipment status

Requirements

Questions

Is there a free X12 parser for Node.js?

Yes. ediFabric Native is included in the free Community plan, which never expires: unlimited operations for the first 14 days, then 250 a day, for non-production use. To try it without an account, use the demo serial key bd96a836feca45cb91c86ee65d281f52. Production use starts with the Developer plan at $179 a year.

Do EDI files or PHI leave my servers?

No. The library runs inside your Node.js process and parses, validates and builds files locally. Only the license check goes over the network, and the EDI file is never part of it. With an Enterprise or Perpetual offline token, translation runs fully offline.

Which X12 transactions and versions does it support?

Any X12 transaction set that has a model: HIPAA 5010 claims, remittances, enrollment and eligibility, and supply-chain transactions such as 850, 856 and 810, in the X12 versions the EDI spec library covers. Models download on demand from the EDI spec library, or you map local OpenEDI JSON models, including ones customized for a trading partner.

Does it validate HIPAA and generate 999 acknowledgments?

Yes. It validates up to HIPAA SNIP level 4 and returns each error with the segment it's in, and it generates 999, 997 and TA1 acknowledgments in the same call.

Can it parse EDIFACT, HL7 or NCPDP?

ediFabric Native supports X12 and HIPAA today. For EDIFACT, EANCOM, HL7, NCPDP, VDA and flat files, use ediFabric .NET or the ediFabric Cloud REST API, which come with the same plan.

Also for Python · Java · Go · Rust, C# and C, in ediFabric Native. For typed C# objects and all ten EDI standards, see ediFabric .NET.

Parse your first X12 file in Node.js

Install the package, use the demo serial key, and parse your file. Sign up free for Community when you need your own key: no credit card, and it never expires.