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 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则