{"record":{"id":"72dc82207a301edd","repo":"ansible/ansible","slug":"key-of-type-type-k-name-r-is-not-json-seria","errorCode":null,"errorMessage":"Key of type {type(k).__name__!r} is not JSON serializable by the {cls.profile_name!r} profile.","messagePattern":"Key of type (.+?) is not JSON serializable by the (.+?) profile\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/ansible/module_utils/_internal/_json/_profiles/__init__.py","lineNumber":212,"sourceCode":"\n    @classmethod\n    def post_init(cls) -> None:\n        pass\n\n    @classmethod\n    def maybe_wrap(cls, o: t.Any) -> t.Any:\n        if type(o) in cls._unwrapped_json_types:\n            return o\n\n        return _WrappedValue(o)\n\n    @classmethod\n    def handle_key(cls, k: t.Any) -> t.Any:\n        \"\"\"Validation/conversion hook before a dict key is serialized. The default implementation only accepts str-typed keys.\"\"\"\n        # NOTE: Since JSON requires string keys, there is no support for preserving tags on dictionary keys during serialization.\n\n        if not isinstance(k, str):  # DTFIX-FUTURE: optimize this to use all known str-derived types in type map / allowed types\n            raise TypeError(f'Key of type {type(k).__name__!r} is not JSON serializable by the {cls.profile_name!r} profile.')\n\n        return k\n\n    @classmethod\n    def _handle_key_str_fallback(cls, k: t.Any) -> t.Any:\n        \"\"\"Legacy implementations should use this key handler for backward compatibility with stdlib JSON key conversion quirks.\"\"\"\n        # DTFIX-FUTURE: optimized exact-type table lookup first\n\n        if isinstance(k, str):\n            return k\n\n        if k is None or isinstance(k, (int, float)):\n            return json.dumps(k)\n\n        raise TypeError(f'Key of type {type(k).__name__!r} is not JSON serializable by the {cls.profile_name!r} profile.')\n\n    @classmethod\n    def default(cls, o: t.Any) -> t.Any:","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/ansible/ansible/blob/9cf16a4aca7898481c257f1e17ad28d0b67b1f85/lib/ansible/module_utils/_internal/_json/_profiles/__init__.py#L194-L230","documentation":"Error \"Key of type {type(k).__name__!r} is not JSON serializable by the {cls.profile_name!r} profile.\" thrown in ansible/ansible.","triggerScenarios":"Thrown at lib/ansible/module_utils/_internal/_json/_profiles/__init__.py:212 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use string keys in dictionaries that will be JSON serialized.","Convert non-string keys to strings before returning."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9cf16a4aca7898481c257f1e17ad28d0b67b1f85","analyzedAt":"2026-08-15T00:15:47.100Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}