Skip to content
Advertisement

Snowflake Json array/square brackets around all objects

I’m transforming Data in a JSON by using that code and get a result, that is pretty okay. But I need it in another format, so that our agency is able to use the data.

This is the Code I use:

The Result I get is every row as a JSON with squared brackets, which makes absolutely sense:

But what I/our agency needs is every row in {}, limited by comma and all rows enclosed by []:

Think that’s pretty easy…but I cant find a way to put all rows in another array.

Advertisement

Answer

I’m pretty sure you’ll simply want to use the ARRAY_AGG( ) function to get to what you are looking for, example as follows. Note however, if you are pulling lots of data, you might hit a size limit, and have to think of an alternative:

Helpful links:

https://docs.snowflake.com/en/sql-reference/functions/object_construct.html

https://docs.snowflake.com/en/sql-reference/functions/array_agg.html

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement