{"record":{"id":"4154dfbf994e5f38","repo":"HumanSignal/label-studio","slug":"error-loading-json-from-file-key-nif-you-re-t","errorCode":null,"errorMessage":"Error loading JSON from file \"{key}\".\\nIf you're trying to import non-JSON data (images, audio, text, etc.), edit storage settings and enable \"Tasks\" import method","messagePattern":"Error loading JSON from file \"(.+?)\"\\.\\\\nIf you're trying to import non-JSON data \\(images, audio, text, etc\\.\\), edit storage settings and enable \"Tasks\" import method","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"label_studio/io_storages/base_models.py","lineNumber":724,"sourceCode":"                # Check if file should be processed as JSON based on extension\n                # Skip non-JSON files if use_blob_urls is False\n                if check_file_extension and not self.use_blob_urls:\n                    _, ext = os.path.splitext(key.lower())\n                    # Only process files with JSON/JSONL/PARQUET extensions\n                    json_extensions = {'.json', '.jsonl', '.parquet'}\n\n                    if ext and ext not in json_extensions:\n                        raise UnsupportedFileFormatError(\n                            f'File \"{key}\" is not a JSON/JSONL/Parquet file. Only .json, .jsonl, and .parquet files can be processed.\\n'\n                            f\"If you're trying to import non-JSON data (images, audio, text, etc.), \"\n                            f'edit storage settings and enable \"Tasks\" import method'\n                        )\n\n                try:\n                    link_objects = self.get_data(key)\n                except (UnicodeDecodeError, json.decoder.JSONDecodeError) as exc:\n                    logger.debug(exc, exc_info=True)\n                    raise ValueError(\n                        f'Error loading JSON from file \"{key}\".\\nIf you\\'re trying to import non-JSON data '\n                        f'(images, audio, text, etc.), edit storage settings and enable '\n                        f'\"Tasks\" import method'\n                    )\n\n                for link_object in link_objects:\n                    # TODO: batch this loop body with add_task -> add_tasks in a single bulk write.\n                    # See DIA-2062 for prerequisites\n                    try:\n                        task = self.add_task(\n                            self.project,\n                            maximum_annotations,\n                            max_inner_id,\n                            self,\n                            link_object,\n                            link_class=link_class,\n                        )\n                        max_inner_id += 1","sourceCodeStart":706,"sourceCodeEnd":742,"githubUrl":"https://github.com/HumanSignal/label-studio/blob/0b49e9b53917880baf1dd85d574fe5541a9aafb2/label_studio/io_storages/base_models.py#L706-L742","documentation":"Raised by _scan_and_create_links when self.get_data(key) fails to decode/parse the object as JSON — either a UnicodeDecodeError (not UTF-8 text) or json.JSONDecodeError. The generic ValueError wraps the key so the sync job surfaces which file was unreadable.","triggerScenarios":"A file with a .json/.jsonl/.parquet extension whose body is invalid JSON (truncated upload, HTML error page saved as .json), or a UTF-16/latin-1 encoded JSON file, synced via scan_and_create_links.","commonSituations":"Browser-exported JSON saved with a BOM or in UTF-16; partially uploaded/corrupted files; placeholder binary files renamed to .json; a .parquet file being read through a JSON path in older versions.","solutions":["Open the offending key locally and validate it: python -m json.tool file.json — fix the malformed JSON or re-export it","Re-encode the file as UTF-8 without BOM (iconv -f UTF-16 -t UTF-8)","If the file is genuinely not JSON, remove it or change storage import method to 'Tasks' (blob URLs)","If JSONL, confirm each line is valid JSON (some readers expect a whole-file array or per-line objects)"],"exampleFix":"# before\niconv -f UTF-8 -t UTF-16 tasks.json > tasks.json  # sync fails\n# after\niconv -f UTF-16 -t UTF-8 tasks.json > tasks_utf8.json && python -m json.tool tasks_utf8.json > /dev/null","handlingStrategy":"validation","validationCode":"import json\ndef keys_parse_as_json(get_data, keys):\n    bad = []\n    for k in keys:\n        try:\n            data = get_data(k)\n            json.loads(data if isinstance(data, str) else data.decode('utf-8'))\n        except Exception:\n            bad.append(k)\n    return not bad, bad","typeGuard":"def is_utf8_json_bytes(b):\n    if not isinstance(b, (bytes, bytearray)):\n        return False\n    try:\n        json.loads(b.decode('utf-8'))\n        return True\n    except (UnicodeDecodeError, json.JSONDecodeError):\n        return False","tryCatchPattern":"try:\n    storage.scan_and_create_links()\nexcept ValueError as e:\n    logger.error('Unparseable storage object: %s', e)\n    # repair/re-encode the named file before resyncing","preventionTips":["Run python -m json.tool on every file before uploading","Always upload UTF-8 (no BOM, not UTF-16)","Check uploads completed fully (checksum/size) before syncing","Don't save HTML error pages with a .json extension"],"tags":["json","storage","parsing","encoding"],"backgroundTag":"invalid-json","analyzedSha":"0b49e9b53917880baf1dd85d574fe5541a9aafb2","analyzedAt":"2026-08-29T00:39:52.578Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}