{"record":{"id":"5aa0f9651831ab2f","repo":"apache/beam","slug":"cannot-convert-s-from-a-json-value","errorCode":null,"errorMessage":"Cannot convert %s from a JSON value.","messagePattern":"Cannot convert (.+?) from a JSON value\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/internal/gcp/json_value.py","lineNumber":165,"sourceCode":"    if v.string_value is not None:\n      return v.string_value\n    elif v.boolean_value is not None:\n      return v.boolean_value\n    elif v.integer_value is not None:\n      return v.integer_value\n    elif v.double_value is not None:\n      return v.double_value\n    elif v.array_value is not None:\n      return from_json_value(v.array_value)\n    elif v.object_value is not None:\n      return from_json_value(v.object_value)\n    elif v.is_null:\n      return None\n  elif isinstance(v, extra_types.JsonArray):\n    return [from_json_value(e) for e in v.entries]\n  elif isinstance(v, extra_types.JsonObject):\n    return {p.key: from_json_value(p.value) for p in v.properties}\n  raise TypeError('Cannot convert %s from a JSON value.' % repr(v))\n","sourceCodeStart":147,"sourceCodeEnd":166,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/internal/gcp/json_value.py#L147-L166","documentation":"apache_beam.internal.gcp.json_value.from_json_value converts extra_types.JsonValue/JsonArray/JsonObject protobufs back into plain Python objects. If the value passed is not one of these recognized proto wrapper types (e.g. a raw primitive or a foreign proto message), the function cannot dispatch and raises TypeError with the repr of the value.","triggerScenarios":"Calling from_json_value(v) where v is not an instance of extra_types.JsonValue, JsonArray, or JsonObject — e.g. passing a raw Python dict, a string, or a different protobuf message type.","commonSituations":"Users receiving JSON responses and passing raw parsed dicts instead of the JsonValue proto; mixing up raw JSON strings with JsonValue objects when working with BigQuery/Beam internal APIs.","solutions":["Ensure the input is a extra_types.JsonValue/JsonArray/JsonObject proto, not a raw dict or string","If you have raw JSON, wrap it: extra_types.JsonValue(string_value=json.dumps(obj)) or use a JSON parser that produces JsonValue protos","Use json.loads on raw bytes/str instead of from_json_value, which is only for the proto representation"],"exampleFix":"// before\nfrom apache_beam.internal.gcp.json_value import from_json_value\nobj = from_json_value({'a': 1})  # TypeError\n// after\nimport json\nfrom apache_beam.internal.gcp import json_value\nfrom apache_beam.portability.api import schema_pb2\njv = json_value.to_json_value({'a': 1})\nobj = json_value.from_json_value(jv)","handlingStrategy":"type-guard","validationCode":"from apache_beam.portability.api import external_descriptors\nfrom apache_beam.internal.gcp import json_value\nisinstance(v, (json_value.extra_types.JsonValue, json_value.extra_types.JsonArray, json_value.extra_types.JsonObject))","typeGuard":"from apache_beam.internal.gcp import json_value\ndef is_json_value(v):\n    t = json_value.extra_types\n    return isinstance(v, (t.JsonValue, t.JsonArray, t.JsonObject))","tryCatchPattern":"try:\n    obj = from_json_value(v)\nexcept TypeError:\n    import json\n    obj = json.loads(v)  # fallback for raw JSON payloads","preventionTips":["Only pass protos produced by to_json_value (or Beam APIs) into from_json_value","Keep raw-JSON handling in json.loads, separate from JsonValue proto handling","Check the type with isinstance(JsonValue) before converting"],"tags":["python","type-error","deserialization","json","google-cloud"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}