

Your data already tells the story; nested JSON just hides the plot.
In Snowflake, most modern customer, product, and event data lands as VARIANT columns full of JSON. That’s perfect for ingestion speed, but painful when a sales leader wants a clean list of accounts, or a marketing manager needs campaign events by day. The FLATTEN table function in Snowflake turns those tangled arrays and objects into tidy rows and columns, so you can query them with standard SQL, join to other tables, and confidently feed models or dashboards.
By flattening JSON in Snowflake, you unlock:
Now imagine you never again have to click through the console, paste queries, download CSVs, and upload them into Google Sheets. That is where delegation to an AI agent becomes transformative. Instead of a human analyst babysitting every run, an AI agent executes the same Snowflake FLATTEN logic, validates row counts, refreshes your Google Sheets tabs, and notifies stakeholders when it’s done. You get the reliability of a production pipeline with the flexibility of ad‑hoc analysis, and your team finally steps away from the keyboard to work on strategy instead of plumbing.
JSON is everywhere in modern data stacks: product events, marketing logs, CRM webhooks. In Snowflake, that usually means big VARIANT columns that are powerful but hard to report on. The FLATTEN table function is your bridge from messy JSON to clean, tabular data you can send straight into Google Sheets. Let’s walk through three layers of maturity:
Throughout, keep Snowflake’s FLATTEN docs handy: https://docs.snowflake.com/en/sql-reference/functions/flatten and Google Sheets help here: https://support.google.com/docs.
When to use: quick exploration, ad-hoc questions.
Steps:
SELECT * FROM your_table LIMIT 10; and note the VARIANT column (e.g. payload).SELECT
t.id,
f.value AS event
FROM your_table t,
LATERAL FLATTEN(input => t.payload:events) f;
This explodes the events array into multiple rows.PATH or direct JSON path access:SELECT
t.id,
f.value:event_type::string AS event_type,
f.value:timestamp::timestamp AS ts
FROM your_table t,
LATERAL FLATTEN(input => t.payload:events) f;
Pros: Fast to start; great for discovery.
Cons: Manual, error-prone, no scheduling, no direct link to Sheets.
When JSON is messy or deeply nested, use FLATTEN’s options (see: https://docs.snowflake.com/en/sql-reference/functions/flatten#usage-notes):
OUTER => TRUE keeps rows even when the path doesn’t exist, filling NULLs.RECURSIVE => TRUE walks nested structures.MODE controls what to flatten: OBJECT, ARRAY, or BOTH.
Example:
SELECT
t.id,
f.path,
f.index,
f.value
FROM your_table t,
LATERAL FLATTEN(
input => t.payload,
recursive => TRUE,
mode => 'BOTH'
) f;
This is helpful when you’re reverse-engineering unfamiliar JSON.
When to use: repeatable but still human-triggered workflows.
CREATE OR REPLACE VIEW v_events_flat AS
SELECT
t.id,
f.value:event_id::string AS event_id,
f.value:user_id::string AS user_id,
f.value:campaign::string AS campaign,
f.value:created_at::timestamp AS created_at
FROM raw.events t,
LATERAL FLATTEN(input => t.payload:events) f;
Pros: Central logic lives in one place; easier to maintain.
Cons: Still manual exports and refreshes; no built-in Google Sheets sync.
As your team grows, you don’t want analysts downloading CSVs daily. No-code tools can call Snowflake on a schedule and push results into Google Sheets with minimal engineering.
Use a data connector or BI tool that supports Snowflake and Google Sheets. Many let you schedule exports from a SQL query or view.
Typical setup:
v_events_flat).SELECT *
FROM v_events_flat
WHERE created_at >= dateadd(day, -7, current_timestamp());
Pros: No code; business teams can manage; Sheets is always current.
Cons: Limited flexibility around branching logic, QA checks, or multi-step workflows.
Google provides ways to pull data directly into Sheets.
You can:
Pros: Lives entirely in Sheets; great for sales or marketing managers.
Cons: Harder to manage complex JSON logic or multi-table joins outside Snowflake; Sheets becomes the bottleneck for heavy data volumes.
When JSON volumes grow and requirements change weekly, you need something smarter than fixed schedules. This is where an AI agent such as Simular Pro becomes your digital data analyst.
Simular Pro agents can:
Workflow concept: The agent behaves like a trained ops analyst.
Steps:
CREATE OR REPLACE VIEW v_events_flat AS ... (if not created).v_events_flat view.”
Pros:
Cons:
Beyond scheduled jobs, AI agents shine when JSON structures evolve.
Example: You add new event properties to your JSON. Instead of a human spelunking through the structure, the agent can:
FLATTEN with RECURSIVE => TRUE to map out keys and paths.This turns what used to be a half-day of trial-and-error into a few supervised agent runs.
Start at the layer that fits today, but design your Snowflake FLATTEN logic (views and queries) so an AI agent can take over tomorrow without rewriting everything.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.
Block quote
Ordered list
Unordered list
Bold text
Emphasis
Superscript
Subscript
In Snowflake, FLATTEN is a table function that explodes semi-structured data (VARIANT, OBJECT, ARRAY) into multiple rows so you can query it like a normal table. Use it when your data is stored as JSON but your questions are relational: “Show me one row per event”, “Give me each order item”, or “List every property on this object.”
The basic syntax is:
SELECT *
FROM TABLE(FLATTEN(input => your_variant_column));
You often combine FLATTEN with a base table using a LATERAL join:
SELECT t.id, f.value
FROM raw.events t,
LATERAL FLATTEN(input => t.payload:events) f;
This returns one row for each array element under payload:events. From there, you cast out fields with f.value:key::type. Full details are in the docs: https://docs.snowflake.com/en/sql-reference/functions/flatten.
To flatten nested JSON in Snowflake, you chain multiple FLATTEN calls using LATERAL joins, each targeting a deeper level in the structure. Start with the outer object or array, then step into nested arrays.
Example: customer JSON with an orders array:
SELECT
c.customer_id,
f.value:name::string AS name,
o.value:order_id::int AS order_id,
o.value:price::number AS price
FROM customer_data c,
LATERAL FLATTEN(input => c.details) f,
LATERAL FLATTEN(input => f.value:orders) o;
Here, the first FLATTEN unwraps the root JSON object; the second FLATTEN explodes the orders array. For deeper nesting, add more FLATTEN steps or use RECURSIVE => TRUE when exploring structures. See examples in Snowflake’s docs: https://docs.snowflake.com/en/user-guide/querying-semistructured.
By default, FLATTEN drops rows where the target path cannot be expanded or has zero entries. To preserve those rows, use the OUTER => TRUE option. This tells Snowflake to emit one row even when the expansion is empty, filling FLATTEN’s KEY, INDEX, and VALUE columns with NULL.
Example:
SELECT t.id, f.value
FROM raw.events t,
LATERAL FLATTEN(
input => t.payload:events,
outer => TRUE
) f;
This is critical for accurate reporting: you won’t silently lose customers or sessions that happen to have no events. Instead, you’ll see them as rows with NULL event values and can handle them in SQL (e.g. COALESCE, LEFT JOIN). The behavior is described under OUTER in the FLATTEN reference: https://docs.snowflake.com/en/sql-reference/functions/flatten#arguments.
First, isolate your FLATTEN logic in a stable view, then connect that view to Google Sheets. In Snowflake:
CREATE OR REPLACE VIEW v_events_flat AS
SELECT
t.id,
f.value:event_type::string AS event_type,
f.value:ts::timestamp AS ts
FROM raw.events t,
LATERAL FLATTEN(input => t.payload:events) f;
Now you have a clean, tabular interface. To get this into Google Sheets, you can:
SELECT * FROM v_events_flat.Alternatively, export a CSV from Snowflake UI and import it manually into Sheets (File → Import). For help on importing data, see: https://support.google.com/docs/answer/40608.
An AI agent can act like a tireless data ops assistant. Instead of you logging into Snowflake, running FLATTEN queries, exporting results, and updating Google Sheets, the agent does all of that step by step.
A typical workflow looks like this:
Because each action is visible and modifiable, you can audit and improve the workflow over time. This moves your team from manual, fragile routines to a robust, AI-run pipeline that still uses standard Snowflake FLATTEN under the hood.