'Array specified for non-repeated field, Can I load JSON Format "{a:[1,2,3]}" into BQ

I want upload JSON data which is in the below form {a:[1,2,3]}, into BigQuery, I am familiar Record Field-Type with repeat Mode.

I am getting error Array specified for non-repeated field a. which is self explanatory.

Is there any way to achieve this?(any workaround?)



Solution 1:[1]

The key here is how you define the schema. In case you are providing the schema and you wanted to have a repeated field, the should look like the following:


    [
        {
            "name": "id",
            "type": "STRING",
            "mode": "NULLABLE"
        },
        {
            "name": "a",
            "type": "RECORD",
            "mode": "REPEATED",
            "fields": [
                {
                    "name": "number",
                    "type": "NUMERIC",
                    "mode": "NULLABLE"
                }
            ]
        }
    ]

And your data should be processed to be like this:

{
    "id": "23849996594630040",
    "a": [
        {"number": 1}, 
        {"number": 2}, 
        {"number": 3}
    ]
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Malaman