Are nested objects not supposed to be sent to the ...
# community-help
d
Are nested objects not supposed to be sent to the UI as objects? I have them here as strings and not objects
This is the schema:
Copy code
{
    "name": "onde_col_week",
    "enable_nested_fields": True,
    "fields": [
        {
            "name": "id",
            "type": "string"
        },
        {
            "name": "title",
            "type": "string"
        },
        {
            "name": "description",
            "type": "string"
        },
        {
            "name": "url",
            "type": "string"
        },
        {
            "name": "start_time",
            "type": "string"
        },
        {
            "name": "end_time",
            "type": "string"
        },
        {
            "name": "date_start",
            "type": "string"
        },
        {
            "name": "unix_start_time",
            "type": "int32"
        },
        {
            "name": "unix_end_time",
            "type": "int32"
        },
        {
            "name": "categories",
            "optional": True,            
            "type": "string[]"
        },
        {
            "name": "full_address",
            "optional": True,            
            "type": "string"
        },
        {
            "name": "location",
            "optional": True,            
            "type": "geopoint"
        },
        {
            "name": "host",
            "optional": True,
            "type": "object[]",
            "fields": [
                {
                    "name": "name",
                    "type": "string"
                },
                {
                    "name": "linkedin",
                    "type": "string"
                },
                {
                    "name": "instagram",
                    "type": "string"
                },
                {
                    "name": "twitter",
                    "type": "string"
                }                
            ]
        },        
        {
            "name": "embedding",
            "type": "float[]",
            "embed": {
                "from": [
                    "description"
                ],
                "model_config": {
                    "model_name": "openai/text-embedding-3-small",
                    "api_key": openai_api_key
                }
            }
        }

    ]
}
f
You can parse them safely using https://zod.dev/. Fully type-safe and ensuring you have the right schema from the API
d
Yeah I was trying yo just get started quickly in the browser hehe. But I’m already using valibot to parse the schema right now.
k
You can't have a
fields
within a field definition like this:
Copy code
{
            "name": "host",
            "optional": True,
            "type": "object[]",
            "fields": [
                {
                    "name": "name",
                    "type": "string"
                },
                {
                    "name": "linkedin",
                    "type": "string"
                },
                {
                    "name": "instagram",
                    "type": "string"
                },
                {
                    "name": "twitter",
                    "type": "string"
                }                
            ]
        },
To define types for the children of the
host
object array, you have to define them in a flat manner, like this:
Copy code
"fields" [
  {"name": "host", "type": "object[]"},
  {"name": "host.name", "type": "string[]"},
  {"name": "host.linkedin", "type": "string[]"}
]
We have to use
string[]
since fields within an object array are stored as arrays.