I am trying to convert this result where I have a JSON type column, which comes from a sql query
{
"rows": [
{
"columns": {
"jseq": 1,
"Nombre": "0000956_LANZADOR",
"rutaEsquema": "AXIS",
"TipoDeComponente": "SQL",
"value": 0,
"detalleDelComponente": "Solución incidente 956"
}
},
{
"columns": {
"jseq": 2,
"Nombre": "0000956_02_Borrar_Mandatos.sql",
"rutaEsquema": "AXIS",
"TipoDeComponente": "SQL",
"value": 1,
"detalleDelComponente": "Brecha 67"
}
}
]
}
to this
Nombre | rutaEsquema | TipoDeComponente | detalleDelComponente
---------------------------+-------------+------------------+-----------------------
0000956_LANZADOR | AXIS | SQL | Solución incidente 956
0000956_02_Borrar_Mandatos | AXIS | SQL | Brecha 67
I am using Postgresql
json_to_record and json_to_recordset from the JSON processing functions do exactly this. In your case:
SELECT cols.*
FROM json_to_recordset(yourJsonValue -> 'rows') AS rows(columns JSON),
json_to_record(columns) AS cols(
"Nombre" TEXT,
"rutaEsquema" TEXT,
"TipoDeComponente" TEXT,
"detalleDelComponente" TEXT)
online demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With