{"record":{"id":"2cd3fbecc9a123d0","repo":"CoplayDev/unity-mcp","slug":"import-settings-must-be-a-json-object","errorCode":null,"errorMessage":"import_settings must be a JSON object","messagePattern":"import_settings must be a JSON object","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"Server/src/cli/commands/texture.py","lineNumber":251,"sourceCode":"        return value\n    if isinstance(value, (int, float)) and value in (0, 1, 0.0, 1.0):\n        return bool(value)\n    if isinstance(value, str):\n        lowered = value.strip().lower()\n        if lowered in _TRUE_STRINGS:\n            return True\n        if lowered in _FALSE_STRINGS:\n            return False\n    raise ValueError(f\"{name} must be a boolean\")\n\n\ndef _normalize_import_settings(value: Any) -> dict[str, Any]:\n    if value is None:\n        return {}\n    if isinstance(value, str):\n        value = try_parse_json(value, \"import_settings\")\n    if not isinstance(value, dict):\n        raise ValueError(\"import_settings must be a JSON object\")\n\n    result: dict[str, Any] = {}\n\n    if \"texture_type\" in value:\n        result[\"textureType\"] = _map_enum(\n            value[\"texture_type\"], _TEXTURE_TYPES)\n    if \"texture_shape\" in value:\n        result[\"textureShape\"] = _map_enum(\n            value[\"texture_shape\"], _TEXTURE_SHAPES)\n\n    for snake, camel in [\n        (\"srgb\", \"sRGBTexture\"),\n        (\"alpha_is_transparency\", \"alphaIsTransparency\"),\n        (\"readable\", \"isReadable\"),\n        (\"generate_mipmaps\", \"mipmapEnabled\"),\n        (\"compression_crunched\", \"crunchedCompression\"),\n    ]:\n        if snake in value:","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/Server/src/cli/commands/texture.py#L233-L269","documentation":"Thrown by _normalize_import_settings() when, after optional JSON-string parsing, the value is not a dict. Import settings are a map of key/value pairs, so a non-object (array, number, string) is rejected before any field mapping occurs.","triggerScenarios":"Passing --import-settings as a JSON array or scalar, e.g. `--import-settings '[]'` or `--import-settings '\"sprite\"'`, or calling the normalizer with a list. Also when a quoted JSON string parses to a scalar instead of an object.","commonSituations":"A developer passes a single import type string directly instead of an object, or misquotes the JSON so it becomes a scalar. Common when adapting an example that used a bare value.","solutions":["Wrap settings in a JSON object: `--import-settings '{\"texture_type\":\"sprite\"}'`.","Validate the JSON parses to a dict with `python -c \"import json,sys; print(type(json.loads(sys.argv[1])))\" '<value>'`.","Leave --import-settings off entirely to use Unity defaults."],"exampleFix":"// before\n--import-settings 'sprite'\n// after\n--import-settings '{\"texture_type\":\"sprite\"}'","handlingStrategy":"type-guard","validationCode":"import json\nif isinstance(value, str):\n    value = json.loads(value)\nif not isinstance(value, dict):\n    raise ValueError(\"import_settings must be a JSON object\")","typeGuard":"def is_import_settings_obj(v) -> bool:\n    if isinstance(v, str):\n        try:\n            v = json.loads(v)\n        except json.JSONDecodeError:\n            return False\n    return isinstance(v, dict)","tryCatchPattern":"try:\n    settings = _normalize_import_settings(raw)\nexcept ValueError as e:\n    print_error(str(e)); sys.exit(1)","preventionTips":["Wrap import settings in a JSON object.","Omit --import-settings to accept Unity defaults."],"tags":["cli","validation","texture","input-validation","import-settings","json"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}