# Help with defining multiple data types for a CloudQuery source plugin column

**URL:** <https://community.cloudquery.io/t/help-with-defining-multiple-data-types-for-a-cloudquery-source-plugin-column/399>\
**Category:** CloudQuery Plugins\
**Created:** [February 5, 2024, 10:14am UTC](https://community.cloudquery.io/t/help-with-defining-multiple-data-types-for-a-cloudquery-source-plugin-column/399 "2024-02-05T10:14:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![creative-iguana](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@creative-iguana](https://community.cloudquery.io/u/creative-iguana)\
**Post date:** [February 5, 2024, 10:14am UTC](https://community.cloudquery.io/t/help-with-defining-multiple-data-types-for-a-cloudquery-source-plugin-column/399/1 "2024-02-05T10:14:37Z")

</div>

I am building a source plugin using the Python SDK. One of the fields in the response from the REST API can have one of many different types: string, integer, JSON object, datetime. How can I tell CloudQuery to accept all of these types for this column?

I have already tried string, binary, and JSON but each generates errors.

---

<div class="post-metadata">

**Author:** ![martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@martin](https://community.cloudquery.io/u/martin)\
**Post date:** [February 5, 2024, 10:34am UTC](https://community.cloudquery.io/t/help-with-defining-multiple-data-types-for-a-cloudquery-source-plugin-column/399/2 "2024-02-05T10:34:39Z")

</div>

Hi Dan,

I see in the Typeform plugin we have an [example](https://github.com/cloudquery/cloudquery/blob/main/plugins/source/typeform/plugin/tables/forms.py#L25) of using a `JSONType` column.

What errors are you seeing when you try to use JSON?

---

<div class="post-metadata">

**Author:** ![creative-iguana](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@creative-iguana](https://community.cloudquery.io/u/creative-iguana)\
**Post date:** [February 5, 2024, 3:44pm UTC](https://community.cloudquery.io/t/help-with-defining-multiple-data-types-for-a-cloudquery-source-plugin-column/399/3 "2024-02-05T15:44:12Z")

</div>

Here are a few examples of errors:

```auto
json.decoder.JSONDecodeError: Extra data: line 1 column 5 (char 4)

```

```auto
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

```

---

<div class="post-metadata">

**Author:** ![martin](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@martin](https://community.cloudquery.io/u/martin)\
**Post date:** [February 5, 2024, 4:59pm UTC](https://community.cloudquery.io/t/help-with-defining-multiple-data-types-for-a-cloudquery-source-plugin-column/399/4 "2024-02-05T16:59:02Z")

</div>

I think that error is coming from [here](https://github.com/cloudquery/plugin-sdk-python/blob/main/cloudquery/sdk/scalar/json.py#L23) where the data is being converted into a JSON scalar.

Assuming you are setting your Column to `JSONType` for the field that can have many different types, then I think you can force the string into JSON encoding by calling `json.dumps(field)` in the table resolver. For example, borrowing the code from the `typeform` plugin, you would do something like this:

```python
class FormsResolver(TableResolver):
    def __init__ (self, table=None) -> None:
        super(). __init__ (table=table)

    def resolve(self, client: Client, parent_resource) -> Generator[Any, None, None]:
        for form in client.client.list_forms():
            form['jsoncolumn'] = json.dumps(form['jsoncolumn']) # <--- new code
            yield form

```

This can (and probably should be) fixed in the SDK, but it would be good to see if this approach works for you in this case.

---

<div class="post-metadata">

**Author:** ![creative-iguana](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@creative-iguana](https://community.cloudquery.io/u/creative-iguana)\
**Post date:** [February 7, 2024, 7:40am UTC](https://community.cloudquery.io/t/help-with-defining-multiple-data-types-for-a-cloudquery-source-plugin-column/399/5 "2024-02-07T07:40:10Z")

</div>

Thanks! That is working. I needed to make a small change because some of the values are valid JSON and some are not. Here is what I used:

```python
try:
    temp = json.loads(item['field_maybe_json'])
except (json.JSONDecodeError, TypeError):
    item['field_maybe_json'] = json.dumps(item[k])
yield item

```
