Fix bug where json with wrong encoding causes exception