Serialize stream in JSON.