Skip to content

JsonObject does not expose array values #1455

@ajrock

Description

@ajrock

Thanks for stopping by to let us know something could be better!

PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.

Please run down the following list and make sure you've tried the usual "quick fixes":

If you are still having issues, please be sure to include as much information as possible:

Environment details

  • OS type and version:
  • Python version: 3.10
  • pip version: 25.2
  • google-cloud-spanner version: 3.55.0

Steps to reproduce

  1. Have a Json column in Spanner with schema like e.g. {"a": 1, "b": [2,3]}
  2. execute SQL selecting field b
  3. Attempt to index into the array contained by b
  4. error raised

Code example

with my_database.snapshot() as snapshot:
    result = snapshot.execute_sql("SELECT JSON_QUERY(my_json_col, '$."b"') as b_col
isinstance(b_col, google.cloud.spanner_v1.data_types.JsonObject) # True
b_col[0] # raises error 

Stack trace

Traceback (most recent call last):
  File "<string>", line 1, in <module>
KeyError: 0

Basically, I see that holding arrays is seen as possible in JsonObject (

self._is_array = len(args) and isinstance(args[0], (list, tuple))
), and is successfully serialized, but you cannot index into it, if you have need to transform the data in code.


Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/python-spanner API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions