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
demandé il y a 2 mois586 vues
1 réponse
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
répondu il y a 2 mois

Vous n'êtes pas connecté. Se connecter pour publier une réponse.

Une bonne réponse répond clairement à la question, contient des commentaires constructifs et encourage le développement professionnel de la personne qui pose la question.

Instructions pour répondre aux questions