Refactor flatten_json_list