Loading json files from S3 to Redshift using jsonpath file

0

Sample file:

{

"Messages":[

{"col1":"01", "col2":["key":"02","value":"03"] }, {"col1":"01", "col2":["key":"01","value":"03"] }, {"col1":"01", "col2":["key":"00","value":"03"] } ] }

Hi, How to load this sample to file into redshift table so that the column 'key' gets loaded as multiple rows in to the table.

I tried json path file as below and got an error in redshift as Invalid json path file and index out of range { "jsonpaths": [ "$.Messages[].col2[].key" ] }

sravan
asked 2 months ago573 views
1 Answer
1

To load the sample JSON file into Redshift with the key column as multiple rows, you'll need to flatten the nested col2 array. Redshift doesn't directly support flattening nested arrays into rows, so you'll need to preprocess the file. Use a script to flatten the array into separate JSON objects, upload the preprocessed file to S3, and then use a JSONPaths file and the COPY command in Redshift to load the data into a staging table. From there, you can further process the data as needed before inserting it into your target table.

profile picture
EXPERT
answered 2 months 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.

Guidelines for Answering Questions