Handle circular references when encoding the JSON object.