Fix #596

Handle cases where JSON.stringify was being called with circular objects.