[Python] How to store and retrieve complex JSON documents in GridDB using Python Client?

Discussão em 'Python' iniciado por Stack, Junho 3, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to store complex JSON-like documents (e.g., nested dictionaries) in GridDB using the Python client. GridDB supports Key-Container-Row models, but I am unsure how to handle nested objects.

    Here is what I have tried:

    from griddb_python import StoreFactory

    factory = StoreFactory.get_instance()
    gridstore = factory.get_store(host="192.168.0.22", port=10001, cluster_name="Zaigham", username="Zaigham_A", password="admin786")

    container_info = griddb.ContainerInfo(
    name="sensor_data",
    column_info_list=[
    ("id", griddb.Type.INTEGER),
    ("payload", griddb.Type.STRING) # storing as JSON string
    ],
    type=griddb.ContainerType.COLLECTION,
    row_key=True
    )

    gridstore.drop_container("sensor_data")
    container = gridstore.put_container(container_info)

    import json
    data = {
    "id": 1,
    "payload": json.dumps({"temperature": 24.5, "location": {"lat": 12.34, "lon": 56.78}})
    }
    container.put(list(data.values()))


    Is there a better way to handle nested JSON data in GridDB instead of flattening or storing as a string?

    Continue reading...

Compartilhe esta Página