Stop recursive loops when outputting JSON with circular refs