Fix race condition in json decoding