JSON EDM Streaming Parser
json-edm-parser is a streaming JSON parser designed for Node.js environments. Its primary function is to interpret and preserve Entity Data Model (EDM) type information, making it compatible with OData specifications. Specifically, it addresses the common issue where standard JSON parsers might misinterpret numbers (e.g., `12.00` as an integer) by explicitly adding an `"<property>@odata.type": "Edm.Double"` member to objects for values that represent doubles but might otherwise be seen as integers. The package is currently at version 0.1.2 and has not seen updates in approximately nine years, indicating it is no longer actively maintained. Its release cadence was minimal, and its niche focus on OData EDM type preservation within a streaming context differentiates it from general-purpose JSON parsers.
Common errors
-
ERR_REQUIRE_ESM
cause Attempting to `require()` a package that is ESM-only, or more commonly, trying to `import` a CJS-only package like `json-edm-parser` in an ESM module.fixIf in an ESM project, use `const Parser = (await import('json-edm-parser')).Parser;` or ensure your `package.json` specifies `"type": "commonjs"` if you intend to use `require()`. -
TypeError: Parser is not a constructor
cause This typically happens if `require('json-edm-parser')` is called, but the module either doesn't export a `Parser` class, or is imported incorrectly.fixEnsure `const Parser = require('json-edm-parser');` is used in a CommonJS context. If using a transpiler or bundler, verify it handles CJS modules correctly.
Warnings
- breaking This package is a CommonJS module (`require()`) and does not natively support ES Modules (`import`). Direct `import` statements in pure ESM environments will result in errors.
- deprecated The package has not been updated in approximately nine years (last published 9 years ago). It is considered abandoned and may have unaddressed bugs, security vulnerabilities, or compatibility issues with newer Node.js versions.
- gotcha The parser handles large numbers by converting them to strings to preserve precision, which can be unexpected if strict number typing is required. It also explicitly adds `@odata.type` properties, modifying the original JSON structure.
- gotcha The package does not ship with TypeScript type definitions (`.d.ts` files). Using it in a TypeScript project will result in type errors unless custom declarations are provided.
Install
-
npm install json-edm-parser -
yarn add json-edm-parser -
pnpm add json-edm-parser
Imports
- Parser
const Parser = require('json-edm-parser');import { Parser } from 'json-edm-parser'; - Parser (CommonJS)
const Parser = require('json-edm-parser');
Quickstart
import { Parser } from 'json-edm-parser';
const p = new Parser();
let parsedOutput = {};
p.onValue = function (value) {
Object.assign(parsedOutput, value);
};
p.onEnd = function () {
console.log('Final Parsed Output:');
console.log(JSON.stringify(parsedOutput, null, 2));
};
p.onError = function (error) {
console.error('Parsing error:', error.message);
};
p.write('{ "doubleIntNumber": 12.00,');
p.write('"doubleNormalNumber": 1.2,');
p.write('"doubleLargeNumber": 12345678901234546789.0000000000000000000000000001,');
p.write('"int64LargeNumber": 12345678901234567890123456789}');
p.end();
/* Expected output:
{
"doubleIntNumber@odata.type": "Edm.Double",
"doubleIntNumber": "12.00",
"doubleNormalNumber": 1.2,
"doubleLargeNumber@odata.type": "Edm.Double",
"doubleLargeNumber": "12345678901234546789.0000000000000000000000000001",
"int64LargeNumber": "12345678901234567890123456789"
}
*/