aaronhuggins / node-x12

ASC X12 parser, generator, query engine, and mapper; now with support for streams.
https://aaronhuggins.github.io/node-x12/
MIT License
49 stars 14 forks source link

[BUG] Trailers unavailable in JSON #11

Closed wongjasont closed 4 years ago

wongjasont commented 4 years ago

Describe the bug After parsing a valid EDI file, the X12Interchange object can be seen with a trailers attribute but if .toJSON() or .toJSEDINotation() is called, the resulting object only contains headers and no trailers

To Reproduce

const parser = new X12Parser(true);
const parsed = parser.parse(edi); // has Trailers
parsed.toJSON(); // has No Trailers
parsed.toJSEDNotation(); // has No Trailers
JSON.parse(JSON.stringify(parsed)); // has No Trailers

Expected behavior Trailers should be included in the resulting JSON

Environment (please complete the following information):

ahuggins-nhs commented 4 years ago

@wongjasont The design decision was made to omit from the JSON format since the trailers are made to verify the contents, and simply represent the counts and corresponding ID. In JSON, we can tell the IDs, the number of segments in a transaction, the number of transactions, and the number of functional groups by either inspecting the arrays or calling length in most languages. From my perspective, it serves no purpose to include trailers due to this information already existing in the JSON format.

Can you explain further the need for trailers in JSON? Perhaps a use case?

You are also welcome to submit a pull request that implements the trailers.

ahuggins-nhs commented 4 years ago

@wongjasont Since I have received no response, in the last 4 months, I'll be closing this as won't fix. If you can provide a suitable use-case, I'll be happy to review the decision.