Size limitation on JSON.parse?

edited December 2015 in Kinoma Coding

I'm encountering what might be a size limitation in the Kinoma implementation of JSON.parse. The use case is a base64 encoded image passed as part of a JSON object over a websocket. This works just fine with browsers, even mobile ones but it hangs on the Kinoma emulator running on Mac.

The structure of the JSON object is like this: {"image_data": "--large base64 encoded string--", "success": true} The base64 encoded string is around 400K.

The websocket's onmessage callback is called successfully but wen trying to do JSON.parse( (where evt is the first parameter of onmessage) the simulator just hangs.

Is there a known size limitation for JSON.parse or websocket messages and what can be done to overcome it?


  • Answer ✓


    Currently, the JSON parser uses a 32K buffer for incoming strings; this is causing the hang you're seeing. It is a limitation that will likely be revisited at some point in the future, but for the time being, consider the following workaround.

     var jsonData ='"image_data": "') + 1,',','"image_data": "')) -'"image_data": "') - 2);
     var base64 = jsonData;
     var chunk = new Chunk(base64);

    Let me know if this doesn't work for you,


  • Thanks Will,

    How can I do the opposite? Now I need an image that resides in the filesystem to be base64 encoded for sending.

    Reading the file and loading it into a picture element works well:

    var imgBuffer = Files.readChunk(path_to_image);;;

    I would now like to take imgBuffer, do base64 encoding and send over a websocket. How can I do that?

  • Daniel -

    Chunk.toString(), e.g. imgBuffer.toString() encodes the data into a Base64 string.

    Regards, Brian

  • edited December 2015

    That works!

Sign In or Register to comment.