Retrieve, parse, and manipulate JSON data stored in Amazon Redshift tables using built-in functions or the SUPER data type.
COPY orders FROM 's3://bucket/orders/'
IAM_ROLE 'arn:aws:iam::123:role/redshift'
FORMAT AS JSON 's3://bucket/jsonpaths/orders_paths.json';<\/code><\/p>
How can I query JSON string columns?<\/h2>
Call JSON_EXTRACT_PATH_TEXT or JSON_EXTRACT_ARRAY_ELEMENT_TEXT. These return VARCHAR, so cast when you need numeric or date types.<\/p>
SELECT id,
JSON_EXTRACT_PATH_TEXT(extra,'shipping','city') AS city
FROM orders;<\/code><\/p>
How can I query SUPER columns with PartiQL?<\/h2>
SUPER stores raw JSON. Query using the table.col.key<\/code> or col['key']<\/code> syntax. PartiQL automatically un-nests arrays and objects.<\/p>
Example PartiQL query<\/h3>
SELECT o.id, o.details.shipping.city
FROM orders AS o
WHERE o.details.total_amount > 100;<\/code><\/p>
Best practices for JSON in Redshift<\/h2>
Prefer typed columns for high-value fields. Store the rest in a SUPER or JSON column. Create late-materialized views to project JSON keys as columns for BI tools.<\/p>
JSON_SET<\/code> or ||<\/code> to merge objects:
UPDATE orders SET details = details || {'status':'shipped'};<\/code><\/p>