Decode from base64 json, concat, convert to a Blob, createObjectURL and feed back into an img? That's about the simplest way I can think to do it. Either that or blip it onto a canvas. Or convert it back to base64 in the form of a data-URI.
I just recently did some work in a much less sophisticated area of this. For folks who want to efficiently juggle image data into and out of canvas, ImageBitmap is a little known web API that does it very well. Unlike most web APIs dealing with binary data that interfaces with user interaction, you can use it synchronously, and it’s vastly more efficient than juggling base64-blobs-URLs.
That was the 'blip it onto the canvas' approach :D I discovered that ImageBitmap type just recently too, it's been very handy for the little project I'm working on. My data still comes as base64 strings in JSON though.
Yeah you’re gonna have to async once to get the binary thing canvas works well with, but if it’s even remotely stable you can just memoize shuttling ImageBitmap back in as needed. For my use case it was just literally redrawing the same background image things get drawn on top of with an internal data structure that translates to canvas API. Switching from async calls to ImageBitmap basically made the difference between “this flickering is making me question medical facts about myself” and “I can see it lag if I’m trying really hard”. Which isn’t great but it’s more than good enough for what I was trying to solve.
No reason to transfer the image data in JSON, just read the response as an ArrayBuffer. Pass over that and write it into a dataURI with the needed modifications in a single go.
How are you going to do that? There's other things in the payload. If it was just the image in the response you could read it as binary, but remember we want lots of tiny images coupled with titles and other metadata. You can use something other than JSON but it'll need some kind of structure that needs parsing.