Refactor parse_json_error and parse_json