Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:12:26+00:00 2026-06-03T14:12:26+00:00

The problem is that sending large serialized JSON (over 16,000 characters) over a net

  • 0

The problem is that sending large serialized JSON (over 16,000 characters) over a net socket gets split into chunks. Each chunk fires the data event on the receiving end. So simply running JSON.parse() on the incoming data may fail with SyntaxError: Unexpected end of input.

The work around I’ve managed to come up with so far is to append a null character ('\u0000') to the end of the serialized JSON, and check for that on the receiving end. Here is an example:

var partialData = '';
client.on( 'data', function( data ) {
    data = data.toString();
    if ( data.charCodeAt( data.length - 1 ) !== 0 ) {
        partialData += data;
        // if data is incomplete then no need to proceed
        return;
    } else {
        // append all but the null character to the existing partial data
        partialData += data.substr( 0, data.length - 1 );
    }
    // pass parsed data to some function for processing
    workWithData( JSON.parse( partialData ));
    // reset partialData for next data transfer
    partialData = '';
});

One of the failures of this model is if the receiver is connected to multiple sockets, and each socket is sending large JSON files.

The reason I’m doing this is because I need to pass data between two processes running on the same box, and I prefer not to use a port. Hence using a net socket. So there would be two questions: First, is there a better way to quickly pass large JSON data between two Node.js processes? Second, if this is the best way then how can I better handle the case where the serialized JSON is being split into chunks when sent?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:12:27+00:00Added an answer on June 3, 2026 at 2:12 pm
    1. You can use try…catch every time to see if it is a valid json. Not very good performance though.
    2. You can calculate size of your json on sending side and send it before JSON.
    3. You can append a boundary string that’s unlikely be in JSON. Your \u0000 – yes, it seems to be a legit way. But most popular choice is newline.

    4. You can use external libraries like dnode which should already do something I mentioned before. I’d recommend trying that. Really.

    One of the failures of this model is if the receiver is connected to multiple sockets, and each socket is sending large JSON files.

    Use different buffers for every socket. No problem here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am facing a problem in sending large files over bluetooth sockets. Smaller files
I am currently sending large amounts of data over a Java socket, and I
Lets assume that I'm dealing with a service that involves sending large amounts of
Problem: I found that certain sessions are sending a heavy burst of requests to
I've got this nasty problem where sending multiple, large messages in quick succession from
I've encountered an issue when sending large segments of data through a TCP socket,
I am sending soap messages that contains arrays. I have problems with arrays in
Simple problem that I can't figure out... How can I print a '%' character
The problem that I have is somehow very specific. I have to implement a
I have a strange problem that is only happening in a single location. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.