Fix concurrency issue where multiple threads trying to merge data at the same time would produce malformed JSON