{"record":{"id":"a3bccd73cd0ac54b","repo":"pathwaycom/pathway","slug":"object-in-expression-r-has-to-be-a-json-or-seque","errorCode":null,"errorMessage":"Object in {expression!r} has to be a JSON or sequence.","messagePattern":"Object in (.+?) has to be a JSON or sequence\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/pathway/internals/type_interpreter.py","lineNumber":532,"sourceCode":"            # 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):\n                if expression._check_if_exists:\n                    return _wrap(expression, dt.Optional(object_dtype.wrapped))\n                else:\n                    return _wrap(expression, object_dtype.wrapped)\n            assert isinstance(object_dtype, dt.Tuple)\n            if object_dtype == dt.ANY_TUPLE:\n                return _wrap(expression, dt.ANY)","sourceCodeStart":514,"sourceCodeEnd":550,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/internals/type_interpreter.py#L514-L550","documentation":"Pathway's type interpreter raises this TypeError when a JsonGet expression (column.get(...) / column[...]) is applied to a column whose dtype is neither JSON (or Optional[JSON]) nor a sequence type (Array, Tuple, List) nor ANY. The interpreter statically checks column dtypes before the pipeline runs, so this is a schema/type error, not a data error.","triggerScenarios":"Calling .get() or [] on a column typed as a scalar (e.g. int, str, float, Optional[int], Pointer, or a Duration/Date column). Example: table.select(res=table.value.get('key')) where table.value is int or str instead of pw.Json. Also happens after apply_with_type or io.schemas that declare the column as a non-JSON scalar.","commonSituations":"CSV/JSON connector schema declares the field as str instead of pw.Json; developer assumed .get() works on any column; reading JSON strings (not parsed objects) from Kafka/CSV and indexing them directly; column wrapped in Optional of a non-JSON type.","solutions":["Declare the column as pw.Json in the connector schema so .get() is valid on it","If the column holds a JSON string, parse it first (e.g. pw.parse_json(table.col)) before .get()","If the column is a scalar, use the value directly instead of .get()","Cast with .astype(pw.Json) or table.with_columns(col=pw.this.col.astype(pw.Json)) when you know the data is JSON-like"],"exampleFix":"// before\ninput_schema = pw.schema_from_types(value=str)\nt = pw.io.csv.read(path, schema=input_schema)\nout = t.select(res=t.value.get('key'))\n\n// after\ninput_schema = pw.schema_from_types(value=pw.Json)\nt = pw.io.csv.read(path, schema=input_schema)\nout = t.select(res=t.value.get('key'))","handlingStrategy":"type-guard","validationCode":"import pathway as pw\n\ndef can_json_get(col) -> bool:\n    d = col._column.dtype\n    return (\n        d.equivalent_to(pw.Json)\n        or d.equivalent_to(pw.Optional[pw.Json])\n        or isinstance(d, (pw.Array, pw.Tuple, pw.List))\n        or d == pw.ANY\n    )","typeGuard":"from pathway.internals import dtype as dt\n\ndef is_json_or_sequence(dtype) -> bool:\n    return (\n        dtype.equivalent_to(dt.JSON)\n        or dtype.equivalent_to(dt.Optional(dt.JSON))\n        or isinstance(dtype, (dt.Array, dt.Tuple, dt.List))\n        or dtype == dt.ANY\n    )","tryCatchPattern":"try:\n    out = t.select(res=t.value.get('key'))\nexcept TypeError as e:\n    if 'has to be a JSON or sequence' in str(e):\n        t = t.with_columns(value=pw.this.value.astype(pw.Json))\n        out = t.select(res=t.value.get('key'))\n    else:\n        raise","preventionTips":["Declare JSON-valued connector fields as pw.Json in the schema","Print table.schema before using .get()/[] on a column","Parse JSON strings with pw.parse_json before indexing"],"tags":["pathway","types","json","schema"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}