how do a parse x12 in javascript

To parse an X12 file in JavaScript, we can use the x12-parser package available on npm.

Here is an example of how to install and use the package:

npm i x12-parser
17 chars
2 lines
const X12Parser = require('x12-parser');

const parser = new X12Parser();
const result = parser.parse('ISA*00*          *00*          *01*SENDER_ID     *ZZ*RECEIVER_ID   *180619*1505*U*00401*000002141*0*P*:~GS*HC*SENDER_ID*RECEIVER_ID*20180619*1505*2141*X*004010X092A1~ST*270*0001*004010X092A1~BHT*0022*13*10001234*20060501*1319~HL*1**20*1~NM1*PR*2*ABC COMPANY*****PI*842610001~HL*2*1*21*1~NM1*1P*2*JONES*BOB****XX*1234567890~PER*IC*JANE DOE*TE*5555555555*EX*123~HL*3*2*22*0~PAT*19~NM1*IL*1*DARLING*DEBBIE****MI*11122333301~HL*4*3*23*0~NM1*PR*2*ABC COMPANY*****PI*842610001~TRN*1*93175-012547*9877281234~NM1*1P*2*JONES*BOB****XX*1234567890~DMG*D8*19430301~DTP*291*D8*20060501~EQ*30~SE*14*0001~GE*1*2141~IEA*1*000002141~');

console.log(result);
745 chars
7 lines

The output of the parse method will return an object that contains the parsed X12 EDI data.

From here, you can manipulate the parsed data as needed for your particular use case.

gistlibby LogSnag