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
preguntada hace 2 meses586 visualizaciones
1 Respuesta
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
EXPERTO
respondido hace 2 meses

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas