Skip to content

S3 redshift copy command with JSON Array

0

I have a below Json in my s3 bucket. [

{

}

]

"""id": "123",

"name": "Test",

"message_id": "123456789",

"timestamp": "2025-08-04T11:00:44.197145"

Whether this will work in the copy command or not?

asked a year ago254 views

1 Answer
0

When loading JSON data into Amazon Redshift using the COPY command, you can load from JSON data that consists of a set of arrays, but you'll need to use a JSONPaths file to map the array elements to columns.

Based on the JSON structure you've provided (which appears to be an array containing objects), you would need to create a JSONPaths file to map the JSON attributes to your table columns. The JSONPaths file would contain JSONPath expressions that specify the path to each element in your JSON structure.

For example, if your table has columns for id, name, message_id, and timestamp, your JSONPaths file might look like:

{
"jsonpaths": [
"$[0].id",
"$[0].name",
"$[0].message_id",
"$[0].timestamp"
]
}

Then, in your COPY command, you would specify the location of this JSONPaths file as the argument to the FORMAT JSON option:

COPY your_table
FROM 's3://your-bucket/your-data.json'
IAM_ROLE 'arn:aws:iam::0123456789012:role/YourRedshiftRole'
FORMAT JSON 's3://your-bucket/your-jsonpaths-file.json';

Note that the JSONPaths file must be a separate file in your S3 bucket, and its path must be explicitly referenced in the COPY command. It cannot be a key prefix, and you should ensure it doesn't have the same prefix as your data files to avoid COPY reading it as a data file.
Sources
COPY examples - Amazon Redshift
Using COPY to load data into SUPER columns - Amazon Redshift
Data format parameters - Amazon Redshift

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.