DonutEspresso / big-json

A stream based implementation of JSON.parse and JSON.stringify for big POJOs
MIT License
114 stars 9 forks source link

big-json createStringifyStream unable to handle blank keys in JSON object #25

Open theheapdump opened 2 years ago

theheapdump commented 2 years ago

PFB the sample programt to reproduce this

const bigJSON = require('big-json');

function tryit() { const objBlankKeyBlankVal = {'': 'data1', 'key1': ''}; console.log('STRINGIFY OUTPUT ' , JSON.stringify(objBlankKeyBlankVal)); let str = ''; bigJSON.createStringifyStream({body: objBlankKeyBlankVal}).on( 'data', (d) => { str += d.toString(); console.log("STR = " + str); }); }

tryit();

PFB the output

STRINGIGY OUTPUT {"":"data1","key1":""} STR = { STR = {"data1" STR = {"data1", STR = {"data1","key1": STR = {"data1","key1":"" STR = {"data1","key1":""}

Please notice - the blank key is lost and stringified JSON is malformed

The reverse actually works

Sample Code

function tryit() { const jsonParseStream = bigJSON.createParseStream(); Stream.Readable.from(JSON.stringify({'': 'data1', 'key1': ''})) .pipe(jsonParseStream); jsonParseStream.on('data', (data) => { console.log('TEST-VALUE : ', data); }); }

Sample Output

TEST-VALUE : { '': 'data1', key1: '' }

theheapdump commented 2 years ago

repro.txt

theheapdump commented 2 years ago

https://github.com/Faleij/json-stream-stringify/issues/28

DonutEspresso commented 2 years ago

In the latest release I picked up ^3.0.0 of json-stream-stringify. Let me know if that addresses this issue.