Код: Выделить всё
{'status': 'done',
'nextLogId': 'AQAAAXb',
'logs': [{'content': {'service': 't2pipeline',
'tags': ['tag1:value1', 'tag2:value2', 'tag3:value3'],
'timestamp': '2021-01-05T05:25:03.416Z',
'host': 'i-00e17',
'attributes': {'caller': 'psignal/state_machine.go:451',
'ts': 1609824303.416246,
'level': 'warn'},
'message': 'psignal: Ignoring scte35 segmentation_descriptor (type:Program Start eventID:0 refUTC:Jan 5 05:25:02.387626333): there is an active segment with the same event_id'},
'id': 'AQAAAXb'},
{'content': {'service': 't2pipeline',
'tags': ['tag1:value1', 'tag2:value2', 'tag3:value3'],
'timestamp': '2021-01-05T05:25:03.416Z',
'host': 'i-00e17',
'attributes': {'caller': 'psignal/state_machine.go:713',
't2': {'scte35': {'event_id': 0,
'event_ptr': '0xc009f32b40',
'seg_type_id': 16}},
'ts': 1609824303.4161847,
'level': 'info'},
'message': 'psignal: scte35 segdesc eventID:0 type:Program Start'},
'id': 'AQAAAXb'}],
'requestId': 'OVZRd3hv'}
Я конвертирую в строку с помощью json.dumps()
А затем использую re.sub(), чтобы удалить раздел 'tags': [], из ответа и вернуть строку следующим образом
Код: Выделить всё
res = re.sub(r'"tags": \[.*"\],\s', "", response_string)
Код: Выделить всё
print(res)
Код: Выделить всё
{"status": "done",
"nextLogId": "AQAAAXb",
"logs": [{"content": {"service": "t2pipeline",
"timestamp": "2021-01-05T05:25:03.416Z",
"host": "i-00e17b8e872ec7d05",
"attributes": {"caller": "psignal/state_machine.go:713",
"t2": {"scte35": {"event_id": 0,
"event_ptr": "0xc009f32b40",
"seg_type_id": 16}},
"ts": 1609824303.4161847,
"level": "info"},
"message": "psignal: scte35 segdesc eventID:0 type:Program Start"},
"id": "AQAAAXb"}],
"requestId": "OVZRd3hv"}
Примечание. Поскольку я не могу удалить по ключу, я думаю, что единственный способ удалить содержимое - это обрабатывать ответ как строку и удалять тег с помощью регулярного выражения.>
Подробнее здесь: https://stackoverflow.com/questions/656 ... e-brackets
Мобильная версия