{"record":{"id":"778f60ec69fa89c6","repo":"getredash/redash","slug":"couldn-t-find-path-in-response","errorCode":null,"errorMessage":"Couldn't find path {} in response.","messagePattern":"Couldn't find path (.+?) in response\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"redash/query_runner/json_ds.py","lineNumber":77,"sourceCode":"def add_column(columns, column_name, column_type):\n    if _get_column_by_name(columns, column_name) is None:\n        columns.append({\"name\": column_name, \"friendly_name\": column_name, \"type\": column_type})\n\n\ndef _apply_path_search(response, path, default=None):\n    if path is None:\n        return response\n\n    path_parts = path.split(\".\")\n    path_parts.reverse()\n    while len(path_parts) > 0:\n        current_path = path_parts.pop()\n        if current_path in response:\n            response = response[current_path]\n        elif default is not None:\n            return default\n        else:\n            raise Exception(\"Couldn't find path {} in response.\".format(path))\n\n    return response\n\n\ndef _normalize_json(data, path):\n    if not data:\n        return None\n    data = _apply_path_search(data, path)\n\n    if isinstance(data, dict):\n        data = [data]\n\n    return data\n\n\ndef _sort_columns_with_fields(columns, fields):\n    if fields:\n        columns = compact([_get_column_by_name(columns, field) for field in fields])","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/getredash/redash/blob/ca79fe988d81cdac9675b412f3dfcab107bc1fbc/redash/query_runner/json_ds.py#L59-L95","documentation":"After fetching JSON, _apply_path_search walks the configured path components into the response dict; if a component key is absent and no default was provided, it raises 'Couldn't find path {} in response.' naming the full missing path.","triggerScenarios":"Query includes path: a.b.c but the API response lacks one of those keys — e.g. pagination or an error payload changed the envelope ({'data': ...} vs direct list), or a typo in the path.","commonSituations":"API version change altering response envelope, endpoint returning an error object on failure, misspelled path keys, differing shapes between first and paginated pages.","solutions":["Run the query without 'path' (or with a shallow path) and inspect the actual response structure in Redash's raw result","Correct path keys to match the real envelope, e.g. path: data.items","Add a 'default' for optional paths so missing keys fall back instead of raising","If the API errors intermittently, use the JSON in a check or wrapper that validates status before querying"],"exampleFix":"# before\npath: results.items\n# after\npath: data.items","handlingStrategy":"validation","validationCode":"def path_exists(obj, path: str) -> bool:\n    cur = obj\n    for part in path.split(\".\"):\n        if isinstance(cur, dict) and part in cur:\n            cur = cur[part]\n        else:\n            return False\n    return True\n\n# usage: fetch once, check path_exists(sample_response, configured_path) before querying","typeGuard":null,"tryCatchPattern":"try:\n    result = runner.run_query(q, user)\nexcept Exception as e:\n    if \"Couldn't find path\" in str(e):\n        run_without_path_to_inspect_envelope_then_fix_path()","preventionTips":["Inspect one raw response before configuring path","Set 'default' for optional path segments","Pin API versions to avoid envelope changes"],"tags":["json-ds","json-path","response-shape"],"backgroundTag":"json-path-missing","analyzedSha":"ca79fe988d81cdac9675b412f3dfcab107bc1fbc","analyzedAt":"2026-08-28T18:32:34.637Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}