Avoid explicit double loop in createJSON