Я новичок в JSON структуре данных, я хочу преобразовать приведенные ниже данные в структуру таблицы в Postgres. Может кто-нибудь подскажет, как это сделать?
Это скрипт, который я использую, но как получить массив child_events?
SELECT CAST(enrolment_info->>'id' as BIGINT) AS id,
CAST(enrolment_info->>'assignee_id' as BIGINT) AS assignee_id,
CAST(enrolment_info->>'event_type' as VARCHAR (50)) AS event_type,
CAST(enrolment_info->>'previous_value'as TEXT) AS previous_value
,CAST (values ->> 'ticket_id' as BIGINT) as ticket_id,
CAST (values ->> 'updater_id' as BIGINT) as updater_id,
CAST (values ->> 'timestamp' as BIGINT) as timestamp,
CAST (values ->> 'via' as VARCHAR (50)) as via,
CAST (values ->> 'event_type' as VARCHAR (50)) as event_type,
CAST (values ->> 'id' as VARCHAR (50)) as id,
CAST (values ->> 'created_at' as timestamp without time zone) as created_at
FROM temp.api_data t, json_array_elements(t.values -> 'child_events') AS enrolment_info
Ниже приведен пример JSON.
{
"child_events": [
{
"id": 55956699,
"via": "Web service",
"via_reference_id": null,
"assignee_id": 456,
"event_type": "Change",
"previous_value": null
},
{
"id": 55956699,
"via": "Web service",
"via_reference_id": null,
"group_id": 21117,
"event_type": "Change",
"previous_value": "24308"
}
],
"id": 55956699,
"ticket_id": 1763,
"updater_id": 515777,
"via": "Web service",
"created_at": "2020-05-04T12:54:08Z",
"event_type": "Audit",
"timestamp": 1588596848,
"system": {
"client": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36",
"ip_address": null,
"latitude": 52.5027,
"location": "Delhi, IND, India",
"longitude": xxxxx
}
}