{"record":{"id":"c1bb27e0ca66cf79","repo":"pathwaycom/pathway","slug":"cannot-get-from-json-none","errorCode":null,"errorMessage":"Cannot get from {Json | None}.","messagePattern":"Cannot get from (.+?)\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/type_interpreter.py","lineNumber":525,"sourceCode":"    ) -> expr.GetExpression:\n        expression = super().eval_get(expression, state=state, **kwargs)\n        object_dtype = expression._object._dtype\n        index_dtype = expression._index._dtype\n        default_dtype = expression._default._dtype\n\n        if object_dtype == dt.JSON:\n            # json\n            if not dt.dtype_issubclass(default_dtype, dt.Optional(dt.JSON)):\n                raise TypeError(\n                    f\"Default must be of type {Json | None}, found {default_dtype.typehint}.\"\n                )\n            if not expression._check_if_exists or default_dtype == dt.JSON:\n                return _wrap(expression, dt.JSON)\n            else:\n                return _wrap(expression, dt.Optional(dt.JSON))\n        elif object_dtype.equivalent_to(dt.Optional(dt.JSON)):\n            # optional json\n            raise TypeError(f\"Cannot get from {Json | None}.\")\n        else:\n            # sequence\n            if (\n                not isinstance(object_dtype, (dt.Array, dt.Tuple, dt.List))\n                and object_dtype != dt.ANY\n            ):\n                raise TypeError(\n                    f\"Object in {expression!r} has to be a JSON or sequence.\"\n                )\n            if index_dtype != dt.INT:\n                raise TypeError(f\"Index in {expression!r} has to be an int.\")\n\n            if isinstance(object_dtype, dt.Array):\n                return _wrap(expression, object_dtype.strip_dimension())\n            if object_dtype == dt.ANY:\n                return _wrap(expression, dt.ANY)\n\n            if isinstance(object_dtype, dt.List):","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/type_interpreter.py#L507-L543","documentation":"Raised when get()/indexing is applied to a column of type Optional(Json) (Json | None). Pathway cannot index into a value that may be None, so unlike the plain-Json case (which is supported), the optional-Json case is rejected outright; the None possibility must be eliminated first.","triggerScenarios":"pw.this.maybe_json.get('key') or pw.this.maybe_json['key'] where the column was declared as Optional[pw.Json] (e.g. json_col: pw.Json | None); columns typed Optional(Json) after outer joins or pw.coalesce with None; get on a field produced by an earlier get(..., optional=True).","commonSituations":"Schemas declaring json: pw.Json | None to model missing payloads; outer-join results where the JSON side is nullable; chaining gets where the first get returns Optional(Json) and the second get is applied directly.","solutions":["Guard with a null check: pw.if_else(pw.this.col.is_not_none(), pw.this.col.get('key'), None)","Remove the None possibility first: pw.coalesce(pw.this.col, pw.Json({})).get('key') or replace_none-style filling with a Json default","Change the schema to non-optional pw.Json and let the connector supply empty objects, or use .apply(lambda d: (d or {}).get('key')) for full Python semantics"],"exampleFix":"# before\nv = pw.this.maybe_json.get(\"key\")  # column is Optional[pw.Json] -> TypeError\n\n# after\nv = pw.if_else(\n    pw.this.maybe_json.is_not_none(),\n    pw.this.maybe_json.get(\"key\"),\n    None,\n)","handlingStrategy":"type-guard","validationCode":"import pathway as pw\n\ndef get_safe(optional_json_ref, key: str):\n    return pw.if_else(\n        optional_json_ref.is_not_none(),\n        optional_json_ref.get(key),\n        None,\n    )","typeGuard":"def is_non_optional_json(dtype) -> bool:\n    import pathway as pw\n    return dtype.equivalent_to(pw.typehints.Json())","tryCatchPattern":"try:\n    v = pw.this.maybe_json.get(\"key\")\nexcept TypeError:\n    v = pw.if_else(\n        pw.this.maybe_json.is_not_none(),\n        pw.this.maybe_json.get(\"key\"),\n        None,\n    )","preventionTips":["Never chain .get() directly on Optional[pw.Json] columns","Fill nullable JSON columns with pw.Json({}) via coalesce before indexing","Prefer non-optional Json in schemas and model absence with empty objects"],"tags":["pathway","json","get","optional","typeerror"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}