JSON EDM Streaming Parser

0.1.2 · abandoned · verified Sun Apr 19

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

Warnings

Install

Imports

Quickstart

This example demonstrates how to use the streaming parser to process a JSON string, capturing the `onValue` events and aggregating the parsed output. It highlights how the parser adds `@odata.type` properties for specific number formats to preserve OData EDM type information.

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"
}
*/

view raw JSON →