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
已提問 2 個月前檢視次數 586 次
1 個回答
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
專家
已回答 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南