Fix JSON being outputted before imagedata is set on load