dominictarr / JSONStream

rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)
Other
1.92k stars 165 forks source link

JSONStream.stringify doesn't work on a huge JSON object #164

Open andy51002000 opened 6 years ago

andy51002000 commented 6 years ago

I was going to convert a huge JSON object to string by JSONStream.stringify but got error below How can I fix this problem?

Unhandled rejection RangeError: Invalid string length at Object.stringify (native) at Stream. (/app/node_modules/JSONStream/index.js:194:23) at Stream.stream.write (/app/node_modules/through/index.js:26:11)

  var transStream = JSONStream.stringify(false);
    transStream.pipe(
        req({
            url: `${process.env.ENDPOINT}`,
            method: 'POST',
            encoding: null
        }, (error, response, body) => {
            if (error) {
                console.log('Error sending message: ', error)
            } else {
                console.log('Response: ', response.body)
            }
        })
    );
    transStream.write(model);
    transStream.end();