I wanted to reach out for any advice on normalizing JSON within brackets. I have made several attempts with json_normalize and also a user defined function to denest any JSON which has worked effortlessly until now (credit goes to Serge de Gosson de Varennes for sharing, thank you!) but I keep running into errors or the user defined functon does not flatten the json data below.
Here is the CSV examples
total_count,start_index,items,items_per_page,filing_history_status
14750,0,"[{'category': 'capital', 'date': '2023-01-18', 'description': 'capital-return-purchase-own-shares', 'links': {'self': '/company/00102498/filing-history/MzM2NjI2NjAwOGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/KFIPMRklI9VLmGnwmLTteT757IXrdIXEweOGPopDAtc'}, 'paper_filed': True, 'type': 'SH03', 'annotations': [{'annotation': 'Clarification hmrc confirmation duty paid', 'category': 'annotation', 'date': '2023-01-18', 'description': 'annotation', 'description_values': {'description': 'Clarification hmrc confirmation duty paid'}, 'type': 'ANNOTATION'}], 'pages': 3, 'barcode': 'ABVEZEGG', 'transaction_id': 'MzM2NjI2NjAwOGFkaXF6a2N4'}, {'category': 'capital', 'date': '2023-01-18', 'description': 'capital-return-purchase-own-shares', 'links': {'self': '/company/00102498/filing-history/MzM2NjI2NjAwNGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/Vnn3SQ93Bjt1i9j0bbte52sVb9GA5gbT9P7J8RRy35I'}, 'paper_filed': True, 'type': 'SH03', 'pages': 5, 'barcode': 'ABVEZEEG', 'transaction_id': 'MzM2NjI2NjAwNGFkaXF6a2N4'}, {'action_date': '2023-01-10', 'category': 'capital', 'date': '2023-01-17', 'description': 'capital-sale-or-transfer-treasury-shares-with-date-currency-capital-figure', 'description_values': {'capital': [{'currency': 'USD', 'figure': '251,229,378', 'date': '2023-01-10'}], 'date': '2023-01-10'}, 'links': {'self': '/company/00102498/filing-history/MzM2NTYyMDc0NmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/kn0cgguEz1QENk-MUsFXRcLUSaUkcc2ds4dLJxRVLDg'}, 'paper_filed': True, 'type': 'SH04', 'pages': 2, 'barcode': 'YBV5MT5S', 'transaction_id': 'MzM2NTYyMDc0NmFkaXF6a2N4'}, {'action_date': '2022-12-23', 'category': 'capital', 'date': '2023-01-17', 'description': 'capital-sale-or-transfer-treasury-shares-with-date-currency-capital-figure', 'description_values': {'capital': [{'currency': 'USD', 'figure': '251,022,732.5', 'date': '2022-12-23'}], 'date': '2022-12-23'}, 'links': {'self': '/company/00102498/filing-history/MzM2NTYyMTIxMmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/9P23zv_wuYQkXdRMEbyDv5wbLM9b06hqGtfOXGyeHPE'}, 'paper_filed': True, 'type': 'SH04', 'pages': 2, 'barcode': 'YBV5MVAI', 'transaction_id': 'MzM2NTYyMTIxMmFkaXF6a2N4'}, {'category': 'capital', 'date': '2023-01-12', 'description': 'capital-return-purchase-own-shares', 'links': {'self': '/company/00102498/filing-history/MzM2NTQzMzkxMmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/EgbaDfsLiwXqwi-w5Hus-QKPdcI1kYmjrTOoLJmiI_4'}, 'paper_filed': True, 'type': 'SH03', 'annotations': [{'annotation': 'Clarification HMRC confirmation received that appropriate duty has been paid on this repurchase.', 'category': 'annotation', 'date': '2023-01-12', 'description': 'annotation', 'description_values': {'description': 'Clarification hmrc confirmation received that appropriate duty has been paid on this repurchase.'}, 'type': 'ANNOTATION'}], 'pages': 3, 'barcode': 'ABUTWG01', 'transaction_id': 'MzM2NTQzMzkxMmFkaXF6a2N4'}, {'category': 'capital', 'date': '2023-01-12', 'description': 'capital-return-purchase-own-shares', 'links': {'self': '/company/00102498/filing-history/MzM2NTQzMzkxMWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/t0ey0FXW0kaaTi9P8Ps-5zM95IG3iTkM3fTHJK2b6dI'}, 'paper_filed': True, 'type': 'SH03', 'annotations': [{'annotation': 'Clarification HMRC confirmation received that appropriate duty has been paid on this repurchase.', 'category': 'annotation', 'date': '2023-01-12', 'description': 'annotation', 'description_values': {'description': 'Clarification hmrc confirmation received that appropriate duty has been paid on this repurchase.'}, 'type': 'ANNOTATION'}], 'pages': 3, 'barcode': 'ABUTWFZU', 'transaction_id': 'MzM2NTQzMzkxMWFkaXF6a2N4'}, {'action_date': '2022-12-22', 'category': 'capital', 'date': '2023-01-09', 'description': 'capital-allotment-shares', 'description_values': {'date': '2022-12-22', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'currency': 'USD', 'figure': '4,760,695,780.25'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2NTAyOTczNGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/XJE1I-VE224cxMQKzzJFSs6hTPS0X0edMLFe2y8ViEU'}, 'type': 'SH01', 'pages': 4, 'barcode': 'XBUUT623', 'transaction_id': 'MzM2NTAyOTczNGFkaXF6a2N4'}, {'action_date': '2022-10-20', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-20', 'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,866,938,331.50', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTgwMWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/WOIUjTKXXPVduvRy3kkNfq6jiwU6fTZPmFAyq9Tc6k8'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXNZF', 'transaction_id': 'MzM2MzUwMTgwMWFkaXF6a2N4'}, {'action_date': '2022-11-07', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-11-07', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,841,613,617', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjMzN2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/vGcWIhrp2T51Xjwvh-DxGZG2s-qX0pee3-uyvVdhq-s'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXQ7U', 'transaction_id': 'MzM2MzUwMjMzN2FkaXF6a2N4'}, {'action_date': '2022-11-08', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,839,188,723.50', 'currency': 'USD'}], 'date': '2022-11-08'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjMzOGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/hX4_Z1O_rV2y6hrqQrxs9qIWNOhTwBlDajSien0XGjM'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXQ83', 'transaction_id': 'MzM2MzUwMjMzOGFkaXF6a2N4'}, {'action_date': '2022-10-26', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,855,749,979.50', 'currency': 'USD'}], 'date': '2022-10-26'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0MWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/esS-R31w94VMTfbEvz1ak5wBWK-dZta5rzlTu6BMTQc'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPGJ', 'transaction_id': 'MzM2MzUwMjE0MWFkaXF6a2N4'}, {'action_date': '2022-10-28', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-28', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'currency': 'USD', 'figure': '4,850,257,261'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0NWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/tvtkhuXRyEhqol5f-NDu1b5D93tykfMTfIJQDWr_iyE'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPBU', 'transaction_id': 'MzM2MzUwMjE0NWFkaXF6a2N4'}, {'action_date': '2022-11-04', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-11-04', 'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'currency': 'USD', 'figure': '4,843,953,910.25'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0OWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/rJTbehtmiovQhzX625TilsiLBPLN0BtTQcQQPQyTz2g'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPCI', 'transaction_id': 'MzM2MzUwMjE0OWFkaXF6a2N4'}, {'action_date': '2022-10-31', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,847,654,519', 'currency': 'USD'}], 'date': '2022-10-31'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0OGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/vnZ4v6xLe61-aj509lCrSZyrciGWfd3JYArL0pJk-h0'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPC2', 'transaction_id': 'MzM2MzUwMjE0OGFkaXF6a2N4'}, {'action_date': '2022-10-25', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-25', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'currency': 'USD', 'figure': '4,858,505,435.25'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjAwNmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/NBMwIr_YjIXCPunxhAZDmZyKXFnMgvC-UCbEPIQYkQA'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXOMA', 'transaction_id': 'MzM2MzUwMjAwNmFkaXF6a2N4'}, {'action_date': '2022-11-03', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'currency': 'USD', 'figure': '4,846,406,664.25'}], 'date': '2022-11-03'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0N2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/JlVWlMQwiT0uw0GsFDi5N3l6YuY6jpLMIIve7Sdxs7c'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPCA', 'transaction_id': 'MzM2MzUwMjE0N2FkaXF6a2N4'}, {'action_date': '2022-10-27', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,852,987,329', 'currency': 'USD'}], 'date': '2022-10-27'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjE0M2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/pA1ufNYMqxg1IqjVXcFx1v2aVCbu8Tt3HYP2jRezWRc'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXPGR', 'transaction_id': 'MzM2MzUwMjE0M2FkaXF6a2N4'}, {'action_date': '2022-10-21', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,864,093,329.75', 'currency': 'USD'}], 'date': '2022-10-21'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjAwM2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/RXHig4q8GhyTAm8n6IQ2adQsYVK6tHOFwvx9j8KJ6dM'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXOKI', 'transaction_id': 'MzM2MzUwMjAwM2FkaXF6a2N4'}, {'action_date': '2022-10-24', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'currency': 'USD', 'figure': '4,861,296,627.75'}], 'date': '2022-10-24'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMjAwNWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/Xab3kKnqCQez6IkyCNR98_krrmTSNuR5usQ7ECT9oLY'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXOM2', 'transaction_id': 'MzM2MzUwMjAwNWFkaXF6a2N4'}, {'action_date': '2022-10-14', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,878,250,683.50', 'currency': 'USD'}], 'date': '2022-10-14'}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTY0MWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/J3Zv7zI7JWvJJX5SjVruBwthLEgx6KfM7PqRC_ahLnU'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXN37', 'transaction_id': 'MzM2MzUwMTY0MWFkaXF6a2N4'}, {'action_date': '2022-10-18', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-18', 'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,872,592,202.25', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTc5OWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/Bpg0KCk-scjaq6aGkI_XXEi7Hq-ia34Yevn0AZN-x9s'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXNVV', 'transaction_id': 'MzM2MzUwMTc5OWFkaXF6a2N4'}, {'action_date': '2022-10-12', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-12', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,884,232,443.25', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTYzN2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/rtHP4aZ76T2H9ufCF5saoxCTydKp9x-6b62xuyLTLeM'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXN5F', 'transaction_id': 'MzM2MzUwMTYzN2FkaXF6a2N4'}, {'action_date': '2022-10-19', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-19', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,869,745,587.75', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTgwMGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/8wMFoih73gPzsW3cKAEHxpPHcNUUfWRc7_jdJCvJTo4'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXO34', 'transaction_id': 'MzM2MzUwMTgwMGFkaXF6a2N4'}, {'action_date': '2022-10-13', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-13', 'capital': [{'figure': '12,706,252', 'currency': 'GBP'}, {'figure': '4,881,240,830.50', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTYzOGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/ugvcHhgmk9x3IthyitanO5Vfk3wRf7q5V366uuMhfcU'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXN6Z', 'transaction_id': 'MzM2MzUwMTYzOGFkaXF6a2N4'}, {'action_date': '2022-10-17', 'category': 'capital', 'date': '2023-01-03', 'description': 'capital-cancellation-shares', 'description_values': {'date': '2022-10-17', 'capital': [{'currency': 'GBP', 'figure': '12,706,252'}, {'figure': '4,875,370,334', 'currency': 'USD'}]}, 'links': {'self': '/company/00102498/filing-history/MzM2MzUwMTY0MmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/7qNdyy_cXHh2bD_kNvz6Tx4CCdLrjqZVuIdCo-ytSx0'}, 'paper_filed': True, 'type': 'SH06', 'pages': 8, 'barcode': 'YBJEXNC8', 'transaction_id': 'MzM2MzUwMTY0MmFkaXF6a2N4'}]",25,filing-history-available
12,0,"[{'action_date': '2022-09-23', 'category': 'confirmation-statement', 'date': '2022-09-30', 'description': 'confirmation-statement-with-no-updates', 'description_values': {'made_up_date': '2022-09-23'}, 'links': {'self': '/company/12098424/filing-history/MzM1MzcxMDIyOWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/wm97CdEs1DD7j6mZuW5lQg1Z9c0OINd9yTIotgAhqtI'}, 'type': 'CS01', 'pages': 3, 'barcode': 'XBDNG7WZ', 'transaction_id': 'MzM1MzcxMDIyOWFkaXF6a2N4'}, {'action_date': '2021-07-31', 'category': 'accounts', 'date': '2022-04-29', 'description': 'accounts-with-accounts-type-total-exemption-full', 'description_values': {'made_up_date': '2021-07-31'}, 'links': {'self': '/company/12098424/filing-history/MzMzNzg3MDQyMGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/4tOH4j8gi_Y20nCkuVkboyhIS6Lzj9hp-5AjXvRCmfE'}, 'type': 'AA', 'pages': 9, 'barcode': 'XB2XP2YY', 'transaction_id': 'MzMzNzg3MDQyMGFkaXF6a2N4'}, {'action_date': '2021-09-23', 'category': 'confirmation-statement', 'date': '2021-10-06', 'description': 'confirmation-statement-with-no-updates', 'description_values': {'made_up_date': '2021-09-23'}, 'links': {'self': '/company/12098424/filing-history/MzMxNjI0Njc4OGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/gejKaHDsYPaEReCs17xJu0zS4PNfMHP43FkjygYeslA'}, 'type': 'CS01', 'pages': 3, 'barcode': 'XAEKJKRD', 'transaction_id': 'MzMxNjI0Njc4OGFkaXF6a2N4'}, {'action_date': '2020-07-31', 'category': 'accounts', 'date': '2021-04-30', 'description': 'accounts-with-accounts-type-total-exemption-full', 'description_values': {'made_up_date': '2020-07-31'}, 'links': {'self': '/company/12098424/filing-history/MzI5OTY1MDE0NGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/G42SZuUKIYaMwqBTv4WFQ_46ITwTCso8JoMQmQBZ-qw'}, 'type': 'AA', 'pages': 9, 'barcode': 'XA3HJGOR', 'transaction_id': 'MzI5OTY1MDE0NGFkaXF6a2N4'}, {'action_date': '2020-09-23', 'category': 'confirmation-statement', 'date': '2020-10-09', 'description': 'confirmation-statement-with-no-updates', 'description_values': {'made_up_date': '2020-09-23'}, 'links': {'self': '/company/12098424/filing-history/MzI4MDA5MDQxMmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/RpF_HoJZui0F68sDrMM3H6hWW66MIevkwtRsGsRoVYg'}, 'type': 'CS01', 'pages': 3, 'barcode': 'X9FAGITS', 'transaction_id': 'MzI4MDA5MDQxMmFkaXF6a2N4'}, {'type': 'CS01', 'action_date': '2019-09-23', 'description_values': {'made_up_date': '2019-09-23'}, 'links': {'self': '/company/12098424/filing-history/MzI0NDg5NDUxM2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/Ekb8A2MZsDtRU7tiVXYx5sXLXuEbhf52kYZ8PdNz9lI'}, 'category': 'confirmation-statement', 'date': '2019-09-23', 'description': 'confirmation-statement-with-updates', 'pages': 4, 'barcode': 'X8EMUH23', 'transaction_id': 'MzI0NDg5NDUxM2FkaXF6a2N4'}, {'type': 'PSC01', 'subcategory': 'notifications', 'action_date': '2019-09-10', 'description_values': {'psc_name': 'Bartosz Pazik', 'notification_date': '2019-09-10'}, 'category': 'persons-with-significant-control', 'links': {'self': '/company/12098424/filing-history/MzI0NDg5MzYzNmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/rAlwZsYfyqfYAV4n_TlFX3c5hqyXmBnKakzKhDL3QL0'}, 'date': '2019-09-23', 'description': 'notification-of-a-person-with-significant-control', 'pages': 2, 'barcode': 'X8EMUDUJ', 'transaction_id': 'MzI0NDg5MzYzNmFkaXF6a2N4'}, {'description_values': {'officer_name': 'Mr Bartosz Pazik', 'appointment_date': '2019-09-10'}, 'category': 'officers', 'links': {'self': '/company/12098424/filing-history/MzI0NDg5MjYxOWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/tK86XekvMQmckMA9Xs8tE9yaBKnCyr0GxrrAcmGUYcU'}, 'date': '2019-09-23', 'description': 'appoint-person-director-company-with-name-date', 'subcategory': 'appointments', 'type': 'AP01', 'action_date': '2019-09-10', 'pages': 2, 'barcode': 'X8EMU9L6', 'transaction_id': 'MzI0NDg5MjYxOWFkaXF6a2N4'}, {'type': 'TM01', 'subcategory': 'termination', 'action_date': '2019-09-10', 'description_values': {'termination_date': '2019-09-10', 'officer_name': 'Lukasz Wojewodzic'}, 'links': {'self': '/company/12098424/filing-history/MzI0NDg5MDc0NGFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/RANnOGoDeSbMP2kqvYY-fh2OyyUfGLqmIZfbgl215oE'}, 'category': 'officers', 'date': '2019-09-23', 'description': 'termination-director-company-with-name-termination-date', 'pages': 1, 'barcode': 'X8EMU1SY', 'transaction_id': 'MzI0NDg5MDc0NGFkaXF6a2N4'}, {'description_values': {'cessation_date': '2019-09-09', 'psc_name': 'Ducers Ltd'}, 'category': 'persons-with-significant-control', 'links': {'self': '/company/12098424/filing-history/MzI0NDg5MDU2OWFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/HdTB7gx7881GBsfsDkfFTEbWnL5kSpnXrtk7k8Fqgz8'}, 'date': '2019-09-23', 'description': 'cessation-of-a-person-with-significant-control', 'subcategory': 'termination', 'type': 'PSC07', 'action_date': '2019-09-09', 'pages': 1, 'barcode': 'X8EMU1CW', 'transaction_id': 'MzI0NDg5MDU2OWFkaXF6a2N4'}, {'description': 'resolution', 'subcategory': 'certificate', 'type': 'RESOLUTIONS', 'description_values': {'description': 'Resolutions'}, 'date': '2019-09-21', 'links': {'self': '/company/12098424/filing-history/MzI0NDgzOTExNmFkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/1RFExUTiTyve6UBTLFym0OQqNVSQ2hecc_5EMI0Z7TU'}, 'category': 'resolution', 'associated_filings': [{'category': 'change-of-name', 'date': '2019-09-21', 'description': 'change-of-name-by-resolution', 'type': 'NM01'}], 'resolutions': [{'category': 'change-of-name', 'description': 'resolution-change-of-name', 'description_values': {'resolution_date': '2019-09-20'}, 'subcategory': 'resolution', 'type': 'RES15'}], 'pages': 3, 'barcode': 'X8EF5GMI', 'transaction_id': 'MzI0NDgzOTExNmFkaXF6a2N4'}, {'links': {'self': '/company/12098424/filing-history/MzIzOTA5NTI0M2FkaXF6a2N4', 'document_metadata': 'https://frontend-doc-api.company-information.service.gov.uk/document/nICiy7Oydb83beqjy1DHvNzoFSFLShsXcDaDnWLt3Cs'}, 'associated_filings': [{'action_date': 1562803200000, 'category': 'capital', 'date': '2019-07-11', 'description': 'statement-of-capital', 'description_values': {'capital': [{'currency': 'GBP', 'figure': '1'}], 'date': '2019-07-11'}, 'type': 'SH01'}, {'category': 'incorporation', 'date': '2019-07-11', 'description': 'model-articles-adopted', 'type': 'MODEL ARTICLES'}], 'date': '2019-07-11', 'category': 'incorporation', 'description': 'incorporation-company', 'type': 'NEWINC', 'pages': 10, 'barcode': 'X89I45EQ', 'transaction_id': 'MzIzOTA5NTI0M2FkaXF6a2N4'}]",25,filing-history-available
The csv is read via Pandas and then I try to flatten it.
import pandas as pd
#credit for this amazing function below and work goes to Serge de Gosson de Varennes
def flatten_nested_json_df(df):
df = df.reset_index()
s = (df.applymap(type) == list).all()
list_columns = s[s].index.tolist()
s = (df.applymap(type) == dict).all()
dict_columns = s[s].index.tolist()
while len(list_columns) > 0 or len(dict_columns) > 0:
new_columns = []
for col in dict_columns:
exploded = pd.json_normalize(df[col]).add_prefix(f'{col}.')
exploded.index = df.index
df = pd.concat([df, exploded], axis=1).drop(columns=[col])
new_columns.extend(exploded.columns) # inplace
for col in list_columns:
# print(f"exploding: {col}")
df = df.drop(columns=[col]).join(df[col].explode().to_frame())
new_columns.append(col)
s = (df[new_columns].applymap(type) == list).all()
list_columns = s[s].index.tolist()
s = (df[new_columns].applymap(type) == dict).all()
dict_columns = s[s].index.tolist()
return df
df1 = pd.read_csv('stackexample.csv')
df1.head() # screenshot highlights data before flattening attempt
Data before attempting to flatten JSON
#attempt at flattening
df2 = flatten_nested_json_df(df1)
df2.head()
Data after attempt to flatten JSON
Thank you for any advice on this matter! I have been stuck on this issue for many days looking at alternatives
Thank you for any suggestions
The function you are using is working, however it needs the data to be in the correct format. The data in column items is in string format, you need to convert it back to data structure (lists and dictionaries).
# https://www.geeksforgeeks.org/python-convert-a-string-representation-of-list-into-list/
from ast import literal_eval
df["items"] = df["items"].apply(literal_eval)
So just use the function in the DataFrame normally.
flatten_nested_json_df(df)
Output:
Related
I'm using the code below to pull in multiple json files into 1 using pagination. When I try to create a spark dataframe I get the error '
java.lang.ArrayStoreException: java.util.HashMap' during spark.read.json. Below the code block I've provided output from printing the 'issues' data set (minus proprietary info). I've done a bit of research and can't figure out what I can try to make this work. Any assistance would be greatly appreciated!!
import requests
import json
limit = 2
startat = 0
issues = []
for page_num in range(2):
startat = page_num*50
url = f"https://URL/rest/api/2/search?jql=TEST&startAt={startat}&maxResults={limit}"
req = requests.get(url, headers={'Accept': 'application/json', 'Authorization': 'Basic xxxxxxxxxxxxxxxxxxxxxxxxxx'})
data = req.json()
issues.extend(data['issues'])
jsonDF = spark.read.json(issues)
jsonDF.printSchema()
[{'expand': 'operations,versionedRepresentations,editmeta,changelog,customfield_10010.requestTypePractice,renderedFields', 'id': '11441', 'self': 'https://my.url.net/rest/api/2/issue/11441', 'key': 'TS-1401', 'fields': {'statuscategorychangedate': '2022-11-29T07:05:17.359-0800', 'issuetype': {'self': 'https://my.url.net/rest/api/2/issuetype/10004', 'id': '10004', 'description': 'Functionality or a feature expressed as a user goal.', 'iconUrl': 'https://my.url.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10315?size=medium', 'name': 'Story', 'subtask': False, 'avatarId': 10315, 'hierarchyLevel': 0}, 'parent': {'id': '11420', 'key': 'TS-1380', 'self': 'https://my.url.net/rest/api/2/issue/11420', 'fields': {'summary': 'Clone30 - Migration Epics', 'status': {'self': 'https://my.url.net/rest/api/2/status/10003', 'description': '', 'iconUrl': 'https://my.url.net/', 'name': 'Backlog', 'id': '10003', 'statusCategory': {'self': 'https://my.url.net/rest/api/2/statuscategory/2', 'id': 2, 'key': 'new', 'colorName': 'blue-gray', 'name': 'To Do'}}, 'priority': {'self': 'https://my.url.net/rest/api/2/priority/3', 'iconUrl': 'https://my.url.net/images/icons/priorities/medium.svg', 'name': 'Medium', 'id': '3'}, 'issuetype': {'self': 'https://my.url.net/rest/api/2/issuetype/10000', 'id': '10000', 'description': 'A big user story that needs to be broken down. Created by Jira Software - do not edit or delete.', 'iconUrl': 'https://my.url.net/images/icons/issuetypes/epic.svg', 'name': 'Epic', 'subtask': False, 'hierarchyLevel': 1}}}, 'timespent': None, 'project': {'self': 'https://my.url.net/rest/api/2/project/10001', 'id': '10001', 'key': 'TS', 'name': 'Project', 'projectTypeKey': 'software', 'simplified': False, 'avatarUrls': {'48x48': 'https://my.url.net/rest/api/2/universal_avatar/view/type/project/avatar/10556', '24x24': 'https://my.url.net/rest/api/2/universal_avatar/view/type/project/avatar/10556?size=small', '16x16': 'https://my.url.net/rest/api/2/universal_avatar/view/type/project/avatar/10556?size=xsmall', '32x32': 'https://my.url.net/rest/api/2/universal_avatar/view/type/project/avatar/10556?size=medium'}}, 'customfield_10033': None, 'fixVersions': [], 'aggregatetimespent': None, 'customfield_10034': [], 'customfield_10035': None, 'resolution': None, 'customfield_10036': None, 'customfield_10037': None, 'customfield_10027': None, 'customfield_10028': None, 'customfield_10029': None, 'resolutiondate': None, 'workratio': -1, 'watches': {'self': 'https://my.url.net/rest/api/2/issue/TS-1401/watchers', 'watchCount': 1, 'isWatching': True}, 'lastViewed': '2022-12-08T10:06:57.022-0800', 'created': '2022-11-29T07:05:16.501-0800', 'customfield_10020': None, 'customfield_10021': None, 'customfield_10022': None, 'priority': {'self': 'https://my.url.net/rest/api/2/priority/3', 'iconUrl': 'https://my.url.net/images/icons/priorities/medium.svg', 'name': 'Medium', 'id': '3'}, 'customfield_10023': None, 'customfield_10024': None, 'customfield_10025': None, 'customfield_10026': None, 'labels': [], 'customfield_10016': None, 'customfield_10017': None, 'customfield_10018': {'hasEpicLinkFieldDependency': False, 'showField': False, 'nonEditableReason': {'reason': 'EPIC_LINK_SHOULD_BE_USED', 'message': 'To set an epic as the parent, use the epic link instead'}}, 'customfield_10019': '0|i008a3:', 'timeestimate': None, 'aggregatetimeoriginalestimate': None, 'versions': [], 'issuelinks': [], 'assignee': None, 'updated': '2022-11-29T07:05:20.759-0800', 'status': {'self': 'https://my.url.net/rest/api/2/status/10003', 'description': '', 'iconUrl': 'https://my.url.net/', 'name': 'Backlog', 'id': '10003', 'statusCategory': {'self': 'https://my.url.net/rest/api/2/statuscategory/2', 'id': 2, 'key': 'new', 'colorName': 'blue-gray', 'name': 'To Do'}}, 'components': [], 'timeoriginalestimate': None, 'description': 'Data owner completes template (understand scope of migration efforts)', 'customfield_10010': None, 'customfield_10014': 'TS-1380', 'customfield_10015': None, 'customfield_10005': None, 'customfield_10006': None, 'customfield_10007': None, 'security': None, 'customfield_10008': None, 'customfield_10009': None, 'aggregatetimeestimate': None, 'summary': 'Template', 'creator': {'self': 'https://my.url.net/rest/api/2/user?accountId=5d669f4bf81f2c0d99ee9e38', 'accountId': '5d669f4bf81f2c0d99ee9e38', 'emailAddress': 'test#aol.com', 'avatarUrls': {'48x48': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '24x24': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '16x16': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '32x32': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png'}, 'displayName': 'Joe Test', 'active': True, 'timeZone': 'America/Los_Angeles', 'accountType': 'atlassian'}, 'subtasks': [{'id': '11442', 'key': 'TS-1402', 'self': 'https://my.url.net/rest/api/2/issue/11442', 'fields': {'summary': 'Complete Template with table/views required (in) and produced (out)', 'status': {'self': 'https://my.url.net/rest/api/2/status/10003', 'description': '', 'iconUrl': 'https://my.url.net/', 'name': 'Backlog', 'id': '10003', 'statusCategory': {'self': 'https://my.url.net/rest/api/2/statuscategory/2', 'id': 2, 'key': 'new', 'colorName': 'blue-gray', 'name': 'To Do'}}, 'priority': {'self': 'https://my.url.net/rest/api/2/priority/3', 'iconUrl': 'https://my.url.net/images/icons/priorities/medium.svg', 'name': 'Medium', 'id': '3'}, 'issuetype': {'self': 'https://my.url.net/rest/api/2/issuetype/10006', 'id': '10006', 'description': "A small piece of work that's part of a larger task.", 'iconUrl': 'https://my.url.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10316?size=medium', 'name': 'Sub-task', 'subtask': True, 'avatarId': 10316, 'hierarchyLevel': -1}}}], 'reporter': {'self': 'https://my.url.net/rest/api/2/user?accountId=5d669f4bf81f2c0d99ee9e38', 'accountId': '5d669f4bf81f2c0d99ee9e38', 'emailAddress': 'test#aol.com', 'avatarUrls': {'48x48': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '24x24': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '16x16': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '32x32': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png'}, 'displayName': 'Joe Test', 'active': True, 'timeZone': 'America/Los_Angeles', 'accountType': 'atlassian'}, 'aggregateprogress': {'progress': 0, 'total': 0}, 'customfield_10001': None, 'customfield_10002': None, 'customfield_10003': None, 'customfield_10004': None, 'customfield_10038': None, 'environment': None, 'duedate': None, 'progress': {'progress': 0, 'total': 0}, 'votes': {'self': 'https://my.url.net/rest/api/2/issue/TS-1401/votes', 'votes': 0, 'hasVoted': False}}}, {'expand': 'operations,versionedRepresentations,editmeta,changelog,customfield_10010.requestTypePractice,renderedFields', 'id': '11438', 'self': 'https://my.url.net/rest/api/2/issue/11438', 'key': 'TS-1398', 'fields': {'statuscategorychangedate': '2022-11-29T07:05:09.126-0800', 'issuetype': {'self': 'https://my.url.net/rest/api/2/issuetype/10004', 'id': '10004', 'description': 'Functionality or a feature expressed as a user goal.', 'iconUrl': 'https://my.url.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10315?size=medium', 'name': 'Story', 'subtask': False, 'avatarId': 10315, 'hierarchyLevel': 0}, 'parent': {'id': '11420', 'key': 'TS-1380', 'self': 'https://my.url.net/rest/api/2/issue/11420', 'fields': {'summary': 'Clone30 - Migration Epics', 'status': {'self': 'https://my.url.net/rest/api/2/status/10003', 'description': '', 'iconUrl': 'https://my.url.net/', 'name': 'Backlog', 'id': '10003', 'statusCategory': {'self': 'https://my.url.net/rest/api/2/statuscategory/2', 'id': 2, 'key': 'new', 'colorName': 'blue-gray', 'name': 'To Do'}}, 'priority': {'self': 'https://my.url.net/rest/api/2/priority/3', 'iconUrl': 'https://my.url.net/images/icons/priorities/medium.svg', 'name': 'Medium', 'id': '3'}, 'issuetype': {'self': 'https://my.url.net/rest/api/2/issuetype/10000', 'id': '10000', 'description': 'A big user story that needs to be broken down. Created by Jira Software - do not edit or delete.', 'iconUrl': 'https://my.url.net/images/icons/issuetypes/epic.svg', 'name': 'Epic', 'subtask': False, 'hierarchyLevel': 1}}}, 'timespent': None, 'project': {'self': 'https://my.url.net/rest/api/2/project/10001', 'id': '10001', 'key': 'TS', 'name': 'Project', 'projectTypeKey': 'software', 'simplified': False, 'avatarUrls': {'48x48': 'https://my.url.net/rest/api/2/universal_avatar/view/type/project/avatar/10556', '24x24': 'https://my.url.net/rest/api/2/universal_avatar/view/type/project/avatar/10556?size=small', '16x16': 'https://my.url.net/rest/api/2/universal_avatar/view/type/project/avatar/10556?size=xsmall', '32x32': 'https://my.url.net/rest/api/2/universal_avatar/view/type/project/avatar/10556?size=medium'}}, 'fixVersions': [], 'customfield_10033': None, 'customfield_10034': [], 'aggregatetimespent': None, 'customfield_10035': None, 'resolution': None, 'customfield_10036': None, 'customfield_10037': None, 'customfield_10027': None, 'customfield_10028': None, 'customfield_10029': None, 'resolutiondate': None, 'workratio': -1, 'lastViewed': None, 'watches': {'self': 'https://my.url.net/rest/api/2/issue/TS-1398/watchers', 'watchCount': 1, 'isWatching': True}, 'created': '2022-11-29T07:05:08.312-0800', 'customfield_10020': None, 'customfield_10021': None, 'customfield_10022': None, 'customfield_10023': None, 'priority': {'self': 'https://my.url.net/rest/api/2/priority/3', 'iconUrl': 'https://my.url.net/images/icons/priorities/medium.svg', 'name': 'Medium', 'id': '3'}, 'customfield_10024': None, 'customfield_10025': None, 'customfield_10026': None, 'labels': [], 'customfield_10016': None, 'customfield_10017': None, 'customfield_10018': {'hasEpicLinkFieldDependency': False, 'showField': False, 'nonEditableReason': {'reason': 'EPIC_LINK_SHOULD_BE_USED', 'message': 'To set an epic as the parent, use the epic link instead'}}, 'customfield_10019': '0|i008ae:y', 'timeestimate': None, 'aggregatetimeoriginalestimate': None, 'versions': [], 'issuelinks': [], 'assignee': None, 'updated': '2022-11-29T07:05:22.417-0800', 'status': {'self': 'https://my.url.net/rest/api/2/status/10003', 'description': '', 'iconUrl': 'https://my.url.net/', 'name': 'Backlog', 'id': '10003', 'statusCategory': {'self': 'https://my.url.net/rest/api/2/statuscategory/2', 'id': 2, 'key': 'new', 'colorName': 'blue-gray', 'name': 'To Do'}}, 'components': [], 'timeoriginalestimate': None, 'description': 'Creating reports/reporting cubes; need to find out reports used', 'customfield_10010': None, 'customfield_10014': 'TS-1380', 'customfield_10015': None, 'customfield_10005': None, 'customfield_10006': None, 'security': None, 'customfield_10007': None, 'customfield_10008': None, 'customfield_10009': None, 'aggregatetimeestimate': None, 'summary': '\xa0create reports/cubes', 'creator': {'self': 'https://my.url.net/rest/api/2/user?accountId=5d669f4bf81f2c0d99ee9e38', 'accountId': '5d669f4bf81f2c0d99ee9e38', 'emailAddress': 'test#aol.com', 'avatarUrls': {'48x48': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '24x24': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '16x16': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '32x32': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png'}, 'displayName': 'Joe Test', 'active': True, 'timeZone': 'America/Los_Angeles', 'accountType': 'atlassian'}, 'subtasks': [{'id': '11439', 'key': 'TS-1399', 'self': 'https://my.url.net/rest/api/2/issue/11439', 'fields': {'summary': 'Confirm: any reporting cubes required using this data are created and in production?', 'status': {'self': 'https://my.url.net/rest/api/2/status/10003', 'description': '', 'iconUrl': 'https://my.url.net/', 'name': 'Backlog', 'id': '10003', 'statusCategory': {'self': 'https://my.url.net/rest/api/2/statuscategory/2', 'id': 2, 'key': 'new', 'colorName': 'blue-gray', 'name': 'To Do'}}, 'priority': {'self': 'https://my.url.net/rest/api/2/priority/3', 'iconUrl': 'https://my.url.net/images/icons/priorities/medium.svg', 'name': 'Medium', 'id': '3'}, 'issuetype': {'self': 'https://my.url.net/rest/api/2/issuetype/10006', 'id': '10006', 'description': "A small piece of work that's part of a larger task.", 'iconUrl': 'https://my.url.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10316?size=medium', 'name': 'Sub-task', 'subtask': True, 'avatarId': 10316, 'hierarchyLevel': -1}}}, {'id': '11440', 'key': 'TS-1400', 'self': 'https://my.url.net/rest/api/2/issue/11440', 'fields': {'summary': 'Confirm: any structured reports using this data are created and in production?', 'status': {'self': 'https://my.url.net/rest/api/2/status/10003', 'description': '', 'iconUrl': 'https://my.url.net/', 'name': 'Backlog', 'id': '10003', 'statusCategory': {'self': 'https://my.url.net/rest/api/2/statuscategory/2', 'id': 2, 'key': 'new', 'colorName': 'blue-gray', 'name': 'To Do'}}, 'priority': {'self': 'https://my.url.net/rest/api/2/priority/3', 'iconUrl': 'https://my.url.net/images/icons/priorities/medium.svg', 'name': 'Medium', 'id': '3'}, 'issuetype': {'self': 'https://my.url.net/rest/api/2/issuetype/10006', 'id': '10006', 'description': "A small piece of work that's part of a larger task.", 'iconUrl': 'https://my.url.net/rest/api/2/universal_avatar/view/type/issuetype/avatar/10316?size=medium', 'name': 'Sub-task', 'subtask': True, 'avatarId': 10316, 'hierarchyLevel': -1}}}], 'reporter': {'self': 'https://my.url.net/rest/api/2/user?accountId=5d669f4bf81f2c0d99ee9e38', 'accountId': '5d669f4bf81f2c0d99ee9e38', 'emailAddress': 'test#aol.com', 'avatarUrls': {'48x48': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '24x24': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '16x16': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png', '32x32': 'https://secure.gravatar.com/avatar/69b7db33e65c274c27a07b28b356e329?d=https%3A%2F%2Favatar-management--avatars.us-west-2.test.png'}, 'displayName': 'Joe Test', 'active': True, 'timeZone': 'America/Los_Angeles', 'accountType': 'atlassian'}, 'aggregateprogress': {'progress': 0, 'total': 0}, 'customfield_10001': None, 'customfield_10002': None, 'customfield_10003': None, 'customfield_10004': None, 'customfield_10038': None, 'environment': None, 'duedate': None, 'progress': {'progress': 0, 'total': 0}, 'votes': {'self': 'https://my.url.net/rest/api/2/issue/TS-1398/votes', 'votes': 0, 'hasVoted': False}}}]
I am trying to append a dictionary to my already existing key "processed_data" where data is saved in the list of dictionaries. I tried several methods as shown in already asked questions but they did not work. This is my schema.
{'_id': ObjectId('5fe46a5b7468e3498124fcbe'), 'metadata': {'_id': ObjectId('5fe4500c7b2c03decd86334f'), 'type': 'VIDEO', 'id': 'o6st4ces9Wg"},"qoeUrl":{"baseUrl":"https://s.youtube.com/api/stats/qoe?cl=348521801', 'user_id': 'fc3240b2d7ef9d33bbb04fd7203e35ea9da54ffb', 'name': 'City Ak47', 'thumbnail': 'https://i.ytimg.com/vi/o6st4ces9Wg/hqdefault.jpg', 'title': 'Alex Bhatti ki Video Viral Ho Gie | How To Become Tiktok Star | City AK47 - YouTube', 'publication_date': 'Sep 17, 2020', 'channel_id': 'UCuo6tBl2MfkWvMPyCqph2LA', 'channel_name': 'City Ak47', 'scrape_date': '2020-12-24 08:23:17.390018', 'regions_allowed': 'AD,AE,AF,AG,AI,AL,AM,AO,AQ,AR,AS,AT,AU,AW,AX,AZ,BA,BB,BD,BE,BF,BG,BH,BI,BJ,BL,BM,BN,BO,BQ,BR,BS,BT,BV,BW,BY,BZ,CA,CC,CD,CF,CG,CH,CI,CK,CL,CM,CN,CO,CR,CU,CV,CW,CX,CY,CZ,DE,DJ,DK,DM,DO,DZ,EC,EE,EG,EH,ER,ES,ET,FI,FJ,FK,FM,FO,FR,GA,GB,GD,GE,GF,GG,GH,GI,GL,GM,GN,GP,GQ,GR,GS,GT,GU,GW,GY,HK,HM,HN,HR,HT,HU,ID,IE,IL,IM,IN,IO,IQ,IR,IS,IT,JE,JM,JO,JP,KE,KG,KH,KI,KM,KN,KP,KR,KW,KY,KZ,LA,LB,LC,LI,LK,LR,LS,LT,LU,LV,LY,MA,MC,MD,ME,MF,MG,MH,MK,ML,MM,MN,MO,MP,MQ,MR,MS,MT,MU,MV,MW,MX,MY,MZ,NA,NC,NE,NF,NG,NI,NL,NO,NP,NR,NU,NZ,OM,PA,PE,PF,PG,PH,PK,PL,PM,PN,PR,PS,PT,PW,PY,QA,RE,RO,RS,RU,RW,SA,SB,SC,SD,SE,SG,SH,SI,SJ,SK,SL,SM,SN,SO,SR,SS,ST,SV,SX,SY,SZ,TC,TD,TF,TG,TH,TJ,TK,TL,TM,TN,TO,TR,TT,TV,TW,TZ,UA,UG,UM,US,UY,UZ,VA,VC,VE,VG,VI,VN,VU,WF,WS,YE,YT,ZA,ZM,ZW', 'views': '663962', 'is_family_friendly': 'true', 'category': 'Entertainment', 'tags': ['AmirFilms', 'Alex Bhatti ki Video Viral Ho Gie | How To Become Tiktok Star | City AK47', 'Tiktok star', 'Tiktok', 'Alex tiktokr', 'Alex bhatti tiktok star', 'Alex bhatti', 'Ayesha bukhari', 'Viral video', 'New video', 'Leak vidro', 'Ayesha leak video', 'Alex bhatti leak video', 'News', 'Tiktik funny video'], 'language': 'en-US', 'width': '480', 'height': '360', 'job_id': '539f61c4183c46448a75cfb65dc40926'}, 'results': {'unique_word_freq': [{'text': 'hai', 'value': 6}, {'text': 'famous', 'value': 4}, {'text': 'allah', 'value': 3}, {'text': 'kar', 'value': 3}, {'text': 'gy', 'value': 3}, {'text': 'ye', 'value': 3}, {'text': 'yeh', 'value': 2}, {'text': 'ka', 'value': 2}, {'text': 'video', 'value': 2}, {'text': 'asee', 'value': 2}, {'text': 'nhi', 'value': 2}, {'text': 'ho', 'value': 2}, {'text': 'tum', 'value': 2}, {'text': 'jao', 'value': 2}, {'text': 'kitna', 'value': 1}, {'text': 'budsoor', 'value': 1}, {'text': 'gundgi', 'value': 1}, {'text': 'dher', 'value': 1}, {'text': 'khusra', 'value': 1}, {'text': 'tiktok', 'value': 1}, {'text': 'kunjuro', 'value': 1}, {'text': 'zanano', 'value': 1}, {'text': 'kaam', 'value': 1}, {'text': 'usko', 'value': 1}, {'text': 'hadyat', 'value': 1}, {'text': 'de', 'value': 1}, {'text': 'ameen', 'value': 1}, {'text': '😔', 'value': 1}, {'text': 'kahn', 'value': 1}, {'text': 'puri', 'value': 1}, {'text': 'kotta', 'value': 1}, {'text': 'ٹک', 'value': 1}, {'text': 'ٹاک', 'value': 1}, {'text': 'ایپ', 'value': 1}, {'text': 'پر', 'value': 1}, {'text': 'پاکستان', 'value': 1}, {'text': 'میں', 'value': 1}, {'text': 'مکمل', 'value': 1}, {'text': 'پابندی', 'value': 1}, {'text': 'لگنی', 'value': 1}, {'text': 'چاہیے', 'value': 1}, {'text': 'leaked', 'value': 1}, {'text': 'purpose', 'value': 1}, {'text': 'fame', 'value': 1}, {'text': 'views', 'value': 1}, {'text': 'mean', 'value': 1}, {'text': 'people', 'value': 1}, {'text': 'like', 'value': 1}, {'text': 'kinda', 'value': 1}, {'text': 'cheap', 'value': 1}, {'text': 'acts', 'value': 1}, {'text': 'inki', 'value': 1}, {'text': 'maa', 'value': 1}, {'text': 'bhano', 'value': 1}, {'text': 'sath', 'value': 1}, {'text': 'bhi', 'value': 1}, {'text': 'hoo', 'value': 1}, {'text': 'pak', 'value': 1}, {'text': 'ko', 'value': 1}, {'text': 'bohot', 'value': 1}, {'text': 'bari', 'value': 1}, {'text': 'sazaa', 'value': 1}, {'text': 'dee', 'value': 1}, {'text': 'duniyan', 'value': 1}, {'text': 'hee', 'value': 1}, {'text': 'dikhaee', 'value': 1}, {'text': 'pata', 'value': 1}, {'text': 'khha', 'value': 1}, {'text': 'jay', 'value': 1}, {'text': 'kiyamat', 'value': 1}, {'text': 'din', 'value': 1}, {'text': 'logo', 'value': 1}, {'text': 'hisab', 'value': 1}, {'text': 'lena', 'value': 1}, {'text': 'log', 'value': 1}, {'text': 'sidah', 'value': 1}, {'text': 'janat', 'value': 1}, {'text': 'chaly', 'value': 1}, {'text': 'baaz', 'value': 1}, {'text': 'ap', 'value': 1}, {'text': 'bakwas', 'value': 1}, {'text': 'band', 'value': 1}, {'text': 'kareen', 'value': 1}, {'text': 'larka', 'value': 1}, {'text': 'bharva', 'value': 1}, {'text': 'bs', 'value': 1}, {'text': 'pakar', 'value': 1}, {'text': 'gal', 'value': 1}, {'text': 'ma', 'value': 1}, {'text': 'dala', 'value': 1}, {'text': 'gaya', 'value': 1}, {'text': 'bahut', 'value': 1}, {'text': 'ghatiya', 'value': 1}, {'text': 'insan', 'value': 1}, {'text': 'tu', 'value': 1}, {'text': 'chakka', 'value': 1}, {'text': 'alex', 'value': 1}, {'text': 'bhatti', 'value': 1}], 'polarity_freq': [{'date': '2020-12-03', 'total': 4, 'positive': 3, 'negative': 1}, {'date': '2020-12-10', 'total': 9, 'positive': 8, 'negative': 1}, {'date': '2020-12-17', 'total': 2, 'positive': 2, 'negative': 0}, {'date': '2020-12-21', 'total': 1, 'positive': 1, 'negative': 0}, {'date': '2020-12-22', 'total': 2, 'positive': 1, 'negative': 1}], 'polarity_dist': [{'name': 'positive', 'value': '15'}, {'name': 'negative', 'value': '3'}], 'assoc': []}, 'processed_data': [{'index': 0, '_id': ObjectId('5fe4500c7b2c03decd863350'), 'channel_id': '/channel/UCg7rf8yXy8wqVxlbnErgdyg', 'clean_text': 'kitna budsoor hai yeh gundgi ka dher khusra', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwniDMBIClPo0sPLX5RDOLPHTJhECMOub-fC0ZTVY6Q=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-22 08:23:17', 'id': 'UgxzkGuC2JpeaZD7El14AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '2 days ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Kitna budsoor hai yeh gundgi ka dher khusra.', 'tokens': ['kitna', 'budsoor', 'hai', 'yeh', 'gundgi', 'ka', 'dher', 'khusra'], 'tokens_no_swords': ['kitna', 'budsoor', 'hai', 'yeh', 'gundgi', 'ka', 'dher', 'khusra'], 'tran_text': 'kitna budsoor hai yeh gundgi ka dher khusra .', 'type': 'COMMENT', 'user_id': 'f7961259b974ba9fae934410fca2e939d3493038', 'user_name': 'jimmi khan', 'video_id': 'o6st4ces9Wg', 'is_hate': '1', 'date': '2020-12-22'}, {'index': 1, '_id': ObjectId('5fe4500c7b2c03decd863351'), 'channel_id': '/channel/UCg7rf8yXy8wqVxlbnErgdyg', 'clean_text': 'tiktok kunjuro zanano ka kaam hai', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwniDMBIClPo0sPLX5RDOLPHTJhECMOub-fC0ZTVY6Q=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-22 08:23:17', 'id': 'UgwntMkhi7J2l2N3MZJ4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '2 days ago (edited)', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Tiktok kunjuro r zanano ka kaam hai.', 'tokens': ['tiktok', 'kunjuro', 'zanano', 'ka', 'kaam', 'hai'], 'tokens_no_swords': ['tiktok', 'kunjuro', 'zanano', 'ka', 'kaam', 'hai'], 'tran_text': 'tiktok kunjuro r zanano ka kaam hai .', 'type': 'COMMENT', 'user_id': 'f7961259b974ba9fae934410fca2e939d3493038', 'user_name': 'jimmi khan', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-22'}, {'index': 2, '_id': ObjectId('5fe4500c7b2c03decd863352'), 'channel_id': '/channel/UCMDNByou1B62upgmnv-UQMw', 'clean_text': 'allah usko hadyat de ameen 😔', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwnik2uW0mzYoagKEYX1_kGY3HDhYd3Ni6UlOxSEHOA=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-21 08:23:17', 'id': 'UgxZrbzomoOLyGEGAjp4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '3 days ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Allah usko hadyat de ameen 😔', 'tokens': ['allah', 'usko', 'hadyat', 'de', 'ameen', '😔'], 'tokens_no_swords': ['allah', 'usko', 'hadyat', 'de', 'ameen', '😔'], 'tran_text': 'allah usko hadyat de ameen 😔', 'type': 'COMMENT', 'user_id': 'da9fe12c7945488a70f56355f8c122d2f35231c5', 'user_name': 'neha Rajput', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-21'}, {'index': 3, '_id': ObjectId('5fe4500c7b2c03decd863353'), 'channel_id': '/channel/UCkl4U918shu8CroBno8-aJg', 'clean_text': '', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwniom0S4ta4uSnNx7yD69NfR4TmOqXPpYxv6_Q=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-17 08:23:17', 'id': 'UgzAfvcluRdyX9yi-JJ4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '1 week ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': '420', 'tokens': [], 'tokens_no_swords': [], 'tran_text': '420', 'type': 'COMMENT', 'user_id': '04b4dd4534a4acf47ba876387d752eda8d3087f6', 'user_name': 'Shahid Khankarachi', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-17'}, {'index': 5, '_id': ObjectId('5fe4500c7b2c03decd863355'), 'channel_id': '/channel/UCoL0h9EyBTNSvKIWIxl6WIg', 'clean_text': 'kahn hai yeh puri video', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwnjNJAzxyS9mOk-R7TF5ICxa0_EQbtgcL3z2Yg=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-17 08:23:17', 'id': 'Ugxx-JvihbK7P8Y8u5x4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '1 week ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Kahn hai yeh puri video', 'tokens': ['kahn', 'hai', 'yeh', 'puri', 'video'], 'tokens_no_swords': ['kahn', 'hai', 'yeh', 'puri', 'video'], 'tran_text': 'kahn hai yeh puri video', 'type': 'COMMENT', 'user_id': '3bc410f7e5133b61e2f2cc790ce6ae2692397778', 'user_name': 'ALISHA ZOYA', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-17'}, {'index': 6, '_id': ObjectId('5fe4500c7b2c03decd863356'), 'channel_id': '/channel/UCsd6TX3yWpNYK55hawyi8qw', 'clean_text': 'kotta', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwnj19uWVIJ75wx27KLjDGDcsVcGtzVtp8SRQ0w=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-10 08:23:17', 'id': 'UgyhHfBJDWHtL73E71N4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '2 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Kotta', 'tokens': ['kotta'], 'tokens_no_swords': ['kotta'], 'tran_text': 'kotta', 'type': 'COMMENT', 'user_id': 'e83b422e66c1bd722306aee6715c3846c32e506b', 'user_name': 'Shakeel Khan', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-10'}, {'index': 7, '_id': ObjectId('5fe4500c7b2c03decd863357'), 'channel_id': '/channel/UCX6LjA5LbC7xMO19yyM7m0Q', 'clean_text': 'ٹک ٹاک ایپ پر پاکستان میں مکمل پابندی لگنی چاہیے', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwni4WpKnrXzHmw2VwT0z5aYnM0T5IhRN0DG3Pmsg=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-10 08:23:17', 'id': 'UgwFILpwDAQKYA9ioMV4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'en', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '2 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'ٹک ٹاک ایپ پر پاکستان میں مکمل پابندی لگنی چاہیے', 'tokens': ['ٹک', 'ٹاک', 'ایپ', 'پر', 'پاکستان', 'میں', 'مکمل', 'پابندی', 'لگنی', 'چاہیے'], 'tokens_no_swords': ['ٹک', 'ٹاک', 'ایپ', 'پر', 'پاکستان', 'میں', 'مکمل', 'پابندی', 'لگنی', 'چاہیے'], 'tran_text': 'ٹک ٹاک ایپ پر پاکستان میں مکمل پابندی لگنی چاہیے', 'type': 'COMMENT', 'user_id': '9ca6083ff6234bd94fc218ef27d12c8b91c2fa33', 'user_name': 'Wahab Mirza', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-10'}, {'index': 8, '_id': ObjectId('5fe4500c7b2c03decd863358'), 'channel_id': '/channel/UCKMvpfSppW24ixWCOmJDu_g', 'clean_text': 'he leaked this video on purpose to get fame and views i mean people like them do these kinda cheap acts to get famous', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwniL8sePcWPsqDg6AOaLsW4nf14XDW3132kC0Q=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-10 08:23:17', 'id': 'Ugz7IdhD6s8zCJ6vHNt4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'en', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '2 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'He leaked this video on purpose to get fame and views...I mean people like them do these kinda cheap acts to get famous.', 'tokens': ['he', 'leaked', 'this', 'video', 'on', 'purpose', 'to', 'get', 'fame', 'and', 'views', 'i', 'mean', 'people', 'like', 'them', 'do', 'these', 'kinda', 'cheap', 'acts', 'to', 'get', 'famous'], 'tokens_no_swords': ['leaked', 'video', 'purpose', 'fame', 'views', 'mean', 'people', 'like', 'kinda', 'cheap', 'acts', 'famous'], 'tran_text': 'he leaked this video on purpose to get fame and views ... i mean people like them do these kinda cheap acts to get famous .', 'type': 'COMMENT', 'user_id': '3f75585892685df3ae4b3d733d9795a719b2d528', 'user_name': 'Ana T', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-10'}, {'index': 9, '_id': ObjectId('5fe4500c7b2c03decd863359'), 'channel_id': '/channel/UCSUGRfHKn5qCNN4TKG3MAkw', 'clean_text': '', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwng6eAHeRd7CcM8mmkCHCA8VI2tqmMNPb1q1MA=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-10 08:23:17', 'id': 'UgwMvbYR29V4ISyic_d4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'en', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '2 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': '03065455318', 'tokens': [], 'tokens_no_swords': [], 'tran_text': '03065455318', 'type': 'COMMENT', 'user_id': '23ac482ba9b36182915c502c13d4cd45b7f7bf1f', 'user_name': 'Ali Rizwan', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-10'}, {'index': 10, '_id': ObjectId('5fe4500c7b2c03decd86335a'), 'channel_id': '/channel/UC-fWQ2vkmngdVliZDkRSiiQ', 'clean_text': 'inki maa bhano sath bhi asee hoo', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwngl0V2Zy_AUGUyIZpMbrBDxqL6pq5AcdF4hNg=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-10 08:23:17', 'id': 'UgzEMbiRNk2ywQHlgxR4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '2 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Inki maa bhano k sath bhi Asee hoo', 'tokens': ['inki', 'maa', 'bhano', 'sath', 'bhi', 'asee', 'hoo'], 'tokens_no_swords': ['inki', 'maa', 'bhano', 'sath', 'bhi', 'asee', 'hoo'], 'tran_text': 'inki maa bhano k sath bhi asee hoo', 'type': 'COMMENT', 'user_id': '2c7e490aa5d0ceca9340c92c3577fa75d3e5a8d3', 'user_name': 'M wali Yousuf', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-10'}, {'index': 11, '_id': ObjectId('5fe4500c7b2c03decd86335b'), 'channel_id': '/channel/UC-fWQ2vkmngdVliZDkRSiiQ', 'clean_text': 'allah pak asee ko bohot bari sazaa dee or duniyan me hee dikhaee', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwngl0V2Zy_AUGUyIZpMbrBDxqL6pq5AcdF4hNg=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-10 08:23:17', 'id': 'Ugyo9YlNa7zuVsSQlZh4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '2 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Allah Pak Asee ko Bohot bari Sazaa Dee Or Duniyan me hee dikhaee', 'tokens': ['allah', 'pak', 'asee', 'ko', 'bohot', 'bari', 'sazaa', 'dee', 'or', 'duniyan', 'me', 'hee', 'dikhaee'], 'tokens_no_swords': ['allah', 'pak', 'asee', 'ko', 'bohot', 'bari', 'sazaa', 'dee', 'duniyan', 'hee', 'dikhaee'], 'tran_text': 'allah pak asee ko bohot bari sazaa dee or duniyan me hee dikhaee', 'type': 'COMMENT', 'user_id': '2c7e490aa5d0ceca9340c92c3577fa75d3e5a8d3', 'user_name': 'M wali Yousuf', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-10'}, {'index': 12, '_id': ObjectId('5fe4500c7b2c03decd86335c'), 'channel_id': '/channel/UCphcNEEoxrp08DARCX7dSNQ', 'clean_text': 'pata nhi famous ho kar khha jay gy kiyamat din allah famous logo hisab lena hai ye nhi tum log famous ho gy or sidah janat chaly jao gy baaz a jao', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwnibNbjcM0UMLW2aTnOD3jfJXlaq2Iq5_hMg3Q-O=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-10 08:23:17', 'id': 'UgzfXCaZHDMSCKPqlKB4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': '1', 'orig_lang': 'unknown', 'published_time_display': '2 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Pata nhi famous ho Kar khha jay gy. Kiyamat k din Allah n famous logo c b hisab lena hai ye nhi k tum log famous ho gy or sidah janat m chaly jao gy. Baaz a jao', 'tokens': ['pata', 'nhi', 'famous', 'ho', 'kar', 'khha', 'jay', 'gy', 'kiyamat', 'din', 'allah', 'famous', 'logo', 'hisab', 'lena', 'hai', 'ye', 'nhi', 'tum', 'log', 'famous', 'ho', 'gy', 'or', 'sidah', 'janat', 'chaly', 'jao', 'gy', 'baaz', 'a', 'jao'], 'tokens_no_swords': ['pata', 'nhi', 'famous', 'ho', 'kar', 'khha', 'jay', 'gy', 'kiyamat', 'din', 'allah', 'famous', 'logo', 'hisab', 'lena', 'hai', 'ye', 'nhi', 'tum', 'log', 'famous', 'ho', 'gy', 'sidah', 'janat', 'chaly', 'jao', 'gy', 'baaz', 'jao'], 'tran_text': 'pata nhi famous ho kar khha jay gy . kiyamat k din allah n famous logo c b hisab lena hai ye nhi k tum log famous ho gy or sidah janat m chaly jao gy . baaz a jao', 'type': 'COMMENT', 'user_id': 'da5c845fbd0a39db29a99a9d620bd8c266956065', 'user_name': 'Rida Khan', 'video_id': 'o6st4ces9Wg', 'is_hate': '1', 'date': '2020-12-10'}, {'index': 13, '_id': ObjectId('5fe4500c7b2c03decd86335d'), 'channel_id': '/channel/UCnVVsV2fd3P0lS9QClU5DCA', 'clean_text': 'ap bakwas band kareen', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwniJxcGaZeKzmvDSUGeX5vFZo3m_ZXQ_yC7-Kw=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-10 08:23:17', 'id': 'UgwzEHvn_WWTbPOzl7x4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '2 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Ap bakwas band kareen', 'tokens': ['ap', 'bakwas', 'band', 'kareen'], 'tokens_no_swords': ['ap', 'bakwas', 'band', 'kareen'], 'tran_text': 'ap bakwas band kareen', 'type': 'COMMENT', 'user_id': 'e51ff2c592a9ad2fe8f6f373c6a2dab117f2c2e9', 'user_name': 'ahmad muaaz', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-10'}, {'index': 14, '_id': ObjectId('5fe4500c7b2c03decd86335e'), 'channel_id': '/channel/UCtbUvUvL0qrREfEzUvJUQKQ', 'clean_text': 'ye larka bharva', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwnjKBfmUKuMzFCtwM-KuKAfq_5y0RA7iez5w9Q=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-10 08:23:17', 'id': 'UgzvW63udc6CEwnsb_J4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '2 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'ye larka bharva', 'tokens': ['ye', 'larka', 'bharva'], 'tokens_no_swords': ['ye', 'larka', 'bharva'], 'tran_text': 'ye larka bharva', 'type': 'COMMENT', 'user_id': '7d7c7165c38c05a96c335421faf6ca3eb9eb1722', 'user_name': 'Rana Waqas', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-10'}, {'index': 15, '_id': ObjectId('5fe4500c7b2c03decd86335f'), 'channel_id': '/channel/UCieduNjSrF2DPawdZh_HesQ', 'clean_text': 'bs kar do tum', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwniOEn-mQTkzQu5ybCc6gjFqSlK8eQF-4RsB6w=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-03 08:23:17', 'id': 'Ugx9gyNwYeVV5DDKsJV4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '3 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'bs kar do tum', 'tokens': ['bs', 'kar', 'do', 'tum'], 'tokens_no_swords': ['bs', 'kar', 'tum'], 'tran_text': 'bs kar do tum', 'type': 'COMMENT', 'user_id': '7339de48d380c9efe854dc9b6660a8fe22c28448', 'user_name': 'sami ali ali', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-03'}, {'index': 16, '_id': ObjectId('5fe4500c7b2c03decd863360'), 'channel_id': '/channel/UCaPZsZzHcOMiDgZ3rkALMFg', 'clean_text': 'is pakar kar gal ma dala gaya', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwnhv4vXDX16Pi0veGMZVUtqiYiYq_XOUp2yTvQ=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-03 08:23:17', 'id': 'UgzC4DaDahEFvjUsJiN4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '3 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Is pakar kar gal ma dala gaya', 'tokens': ['is', 'pakar', 'kar', 'gal', 'ma', 'dala', 'gaya'], 'tokens_no_swords': ['pakar', 'kar', 'gal', 'ma', 'dala', 'gaya'], 'tran_text': 'is pakar kar gal ma dala gaya', 'type': 'COMMENT', 'user_id': 'ae974ed633daab66164b5dcee9340e2ed0b1c455', 'user_name': 'munir gill', 'video_id': 'o6st4ces9Wg', 'is_hate': '1', 'date': '2020-12-03'}, {'index': 17, '_id': ObjectId('5fe4500c7b2c03decd863361'), 'channel_id': '/channel/UCqGRwUGDEBY98v0PcA9BpUQ', 'clean_text': 'bahut ghatiya insan hai', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwnhMts6KGq4VtnvbDuVVatNlFduO6jmHbIRX6A=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-03 08:23:17', 'id': 'UgyyCAdkym_IDptSbNZ4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '3 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Bahut ghatiya insan hai', 'tokens': ['bahut', 'ghatiya', 'insan', 'hai'], 'tokens_no_swords': ['bahut', 'ghatiya', 'insan', 'hai'], 'tran_text': 'bahut ghatiya insan hai', 'type': 'COMMENT', 'user_id': '331593ec91edb449953d775229e7a91727415976', 'user_name': 'Asif Bhatti', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-03'}, {'index': 18, '_id': ObjectId('5fe4500c7b2c03decd863362'), 'channel_id': '/channel/UCBZ0mLPPioFWW1i-kvmZBnA', 'clean_text': 'ye tu chakka hai alex bhatti', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwnggrksT4HvfysI9VkzPzsKIXkcJsPfmWvvNyg=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-03 08:23:17', 'id': 'Ugwh57O9lzDJgzCvKJV4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '3 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Ye tu chakka hai alex bhatti', 'tokens': ['ye', 'tu', 'chakka', 'hai', 'alex', 'bhatti'], 'tokens_no_swords': ['ye', 'tu', 'chakka', 'hai', 'alex', 'bhatti'], 'tran_text': 'ye tu chakka hai alex bhatti', 'type': 'COMMENT', 'user_id': 'ee99e20e5128b5fc14c1972d55625585cf4d0237', 'user_name': 'Khizar Rao', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-03'}]}
I want to append the following dictionary against the "processed_data" key.
{'index': 19, '_id': ObjectId('5fe4500c7b2c03decd863362'), 'channel_id': '/channel/UCBZ0mLPPioFWW1i-kvmZBnA', 'clean_text': 'ye tu chakka hai alex bhatti', 'comment_user_image': 'https://yt3.ggpht.com/ytc/AAUvwnggrksT4HvfysI9VkzPzsKIXkcJsPfmWvvNyg=s48-c-k-c0xffffffff-no-rj-mo', 'datetime': '2020-12-03 08:23:17', 'id': 'Ugwh57O9lzDJgzCvKJV4AaABAg', 'job_id': '539f61c4183c46448a75cfb65dc40926', 'lang': 'ro-ur', 'likes': 0, 'orig_lang': 'unknown', 'published_time_display': '3 weeks ago', 'replies': None, 'reply_to': None, 'scrape_date': '2020-12-24 08:23:17.955821', 'text': 'Ye tu chakka hai alex bhatti', 'tokens': ['ye', 'tu', 'chakka', 'hai', 'alex', 'bhatti'], 'tokens_no_swords': ['ye', 'tu', 'chakka', 'hai', 'alex', 'bhatti'], 'tran_text': 'ye tu chakka hai alex bhatti', 'type': 'COMMENT', 'user_id': 'ee99e20e5128b5fc14c1972d55625585cf4d0237', 'user_name': 'Khizar Rao', 'video_id': 'o6st4ces9Wg', 'is_hate': '0', 'date': '2020-12-03'}
Thanks!
Use update_one() with $push:
from pymongo import MongoClient
from bson import ObjectId
db = MongoClient()['mydatabase']
db.mycollection.insert_one({'_id': ObjectId('5fe46a5b7468e3498124fcbe'),
'processed_data': []})
update = {'index': 19, '_id': ObjectId('5fe4500c7b2c03decd863362'), 'channel_id': 'etc.'}
db.mycollection.update_one({'_id': ObjectId('5fe46a5b7468e3498124fcbe')}, {'$push': {'processed_data': update}})
I am working on a nested dictionary and not able to put it in a dataframe.
This is what it looks like:
{'props': {'initialProps': {'statusCode': 0, '$isMobile': False, '$isIOS': None, '$isAndroid': False, '$host': 'www.tiktok.com', '$pageUrl': '/#alanwalkermusic/video/6816594007829859589', '$language': 'en', '$originalLanguage': 'en', '$languageList': [{'value': 'id', 'alias': 'id-ID', 'label': 'Bahasa Indonesia', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'de', 'alias': 'de-DE', 'label': 'Deutsch', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'en', 'alias': 'en', 'label': 'English', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'es', 'alias': 'es', 'label': 'Español', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'fr', 'alias': 'fr', 'label': 'Français', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'it', 'alias': 'it-IT', 'label': 'Italiano', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'pl', 'alias': 'pl-PL', 'label': 'Polski', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'pt_BR', 'alias': 'pt-BR', 'label': 'Português', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'vi', 'alias': 'vi-VN', 'label': 'Tiếng Việt', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'tr', 'alias': 'tr-TR', 'label': 'Türkçe', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'ru', 'alias': 'ru-RU', 'label': 'Русский', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'hi', 'alias': 'hi-IN', 'label': 'हिन्दी', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'ko', 'alias': 'ko-KR', 'label': '한국어', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'ja', 'alias': 'ja-JP', 'label': '日本語', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'zh_Hant', 'alias': 'zh-Hant-TW', 'label': '繁體中文', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'ar', 'alias': 'ar', 'label': 'العربية', 'children': [{'value': 'default', 'label': ''}]}], '$region': 'DE', '$appId': 1233, '$os': 'windows', '$baseURL': 'm.tiktok.com', '$downloadLink': {'amazon': {'visible': True, 'normal': 'https://www.amazon.com/dp/B0117U0G3M/'}, 'google': {'visible': True, 'normal': 'https://www.tiktok.com/download-link/af/com.zhiliaoapp.musically'}, 'apple': {'visible': True, 'normal': 'https://www.tiktok.com/download-link/af/id835599320'}}, '$abTestVersion': {'clientParameters': '{}', 'clientVersionName': '', 'versionName': '1618717', 'parameters': '{}', 'startTime': '', 'endTime': ''}, '$appType': 'm', '$gray': {'upload': False, 'tea': False}, '$reflowType': 't', '$legalList': [{'title': 'TikTok.com Cookies Policy', 'key': 'tiktok-website-cookies-policy', 'href': 'https://www.tiktok.com/legal/tiktok-website-cookies-policy?lang=en'}, {'title': 'Open Source', 'key': 'open-source', 'href': 'https://www.tiktok.com/legal/open-source?lang=en'}, {'title': 'Virtual Items', 'key': 'virtual-items', 'href': 'https://www.tiktok.com/legal/virtual-items?lang=en'}, {'title': 'Intellectual Property Policy', 'key': 'copyright-policy', 'href': 'https://www.tiktok.com/legal/copyright-policy?lang=en'}, {'title': 'Law Enforcement', 'key': 'law-enforcement', 'href': 'https://www.tiktok.com/legal/law-enforcement?lang=en'}, {'title': 'Privacy Policy', 'key': 'privacy-policy', 'href': 'https://www.tiktok.com/legal/privacy-policy?lang=en'}, {'title': 'Terms of Service', 'key': 'terms-of-use', 'href': 'https://www.tiktok.com/legal/terms-of-use?lang=en'}], '$botType': 'others', '$config': {'covidBanner': {'open': True, 'url': 'https://www.tiktok.com/safety/resources/covid-19', 'background': 'rgba(125,136,227,1)'}}, '$wid': '6819614602332063233'}, 'pageProps': {'serverCode': 200, 'pageState': {'regionAppId': 1233, 'os': 'windows', 'region': 'DE', 'baseURL': 'm.tiktok.com', 'appType': 't', 'fullUrl': 'https://www.tiktok.com/node/share/video/#alanwalkermusic/6816594007829859589'}, 'videoData': {'itemInfos': {'id': '6816594007829859589', 'video': {'urls': ['https://v19.muscdn.com/afefda4362dccd13b93a4d8e79ab5338/5ea477c7/video/tos/useast2a/tos-useast2a-ve-0068c004/7f922f16b9534b80be6523cbb8ba2ce2/?a=1233&br=2652&bt=1326&cr=0&cs=0&dr=0&ds=3&er=&l=202004251147400101150770371E5160EE&lr=tiktok_m&qs=0&rc=MzY3cXc1OjxwdDMzNjczM0ApNDtnNTY1Ojw2N2k8NDU4ZWdoZXBmLjE0ZGBfLS0vMTZzczZjYDEvL2BgMDAzXy0uMC86Yw%3D%3D&vl=&vr='], 'videoMeta': {'width': 540, 'height': 960, 'ratio': 11, 'duration': 11}}, 'covers': ['https://p16-va-default.akamaized.net/obj/tos-maliva-p-0068/8187e5fe9a0f684529910363f5dbe428'], 'authorId': '84453035275386880', 'coversOrigin': ['https://p16-va-default.akamaized.net/obj/tos-maliva-p-0068/7dd18717d8aa4916abc5699c25c09b3e_1587111976'], 'text': 'I’m that friend who can’t stand still when taking photos', 'commentCount': 300, 'diggCount': 14145, 'playCount': 91447, 'shareCount': 29, 'createTime': '1587111974', 'isActivityItem': False, 'warnInfo': [], 'liked': False, 'commentStatus': 0, 'showNotPass': False}, 'authorInfos': {'verified': True, 'secUid': 'MS4wLjABAAAAhS4j-WG_Zq5WJfdV35QEqorNPzc_kkFVNPQmGM6mQIWEg6FOgjS-Dl9eISlYvPDc', 'uniqueId': 'alanwalkermusic', 'userId': '84453035275386880', 'nickName': 'Alan Walker', 'covers': ['https://p16.muscdn.com/img/musically-maliva-obj/1649466056705029~c5_100x100.jpeg']}, 'musicInfos': {'musicId': '6805465027164768258', 'musicName': 'Heading Home', 'authorName': 'Alan Walker, Ruben', 'covers': ['https://p16.muscdn.com/img/musically-maliva-obj/1649466056705029~c5_100x100.jpeg']}, 'authorStats': {'followerCount': 2147815, 'heartCount': '10903873'}, 'challengeInfoList': [], 'duetInfo': '0', 'textExtra': []}, 'shareUser': {'secUid': '', 'userId': '', 'uniqueId': '', 'nickName': '', 'signature': '', 'covers': [], 'coversMedium': [], 'coversLarger': [], 'isSecret': False}, 'shareMeta': {'title': 'Alan Walker on TikTok', 'desc': 'I’m that friend who can’t stand still when taking photos', 'image': {'url': 'http://p16-va-default.akamaized.net/img/tos-maliva-p-0068/8187e5fe9a0f684529910363f5dbe428~tplv-tiktok-play.image', 'width': 540, 'height': 960}}, 'statusCode': 0, 'langList': [{'value': 'id', 'alias': 'id-ID', 'label': 'Bahasa Indonesia', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'de', 'alias': 'de-DE', 'label': 'Deutsch', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'en', 'alias': 'en', 'label': 'English', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'es', 'alias': 'es', 'label': 'Español', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'fr', 'alias': 'fr', 'label': 'Français', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'it', 'alias': 'it-IT', 'label': 'Italiano', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'pl', 'alias': 'pl-PL', 'label': 'Polski', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'pt_BR', 'alias': 'pt-BR', 'label': 'Português', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'vi', 'alias': 'vi-VN', 'label': 'Tiếng Việt', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'tr', 'alias': 'tr-TR', 'label': 'Türkçe', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'ru', 'alias': 'ru-RU', 'label': 'Русский', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'hi', 'alias': 'hi-IN', 'label': 'हिन्दी', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'ko', 'alias': 'ko-KR', 'label': '한국어', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'ja', 'alias': 'ja-JP', 'label': '日本語', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'zh_Hant', 'alias': 'zh-Hant-TW', 'label': '繁體中文', 'children': [{'value': 'default', 'label': ''}]}, {'value': 'ar', 'alias': 'ar', 'label': 'العربية', 'children': [{'value': 'default', 'label': ''}]}], 'webId': '6819614602168567298', 'requestId': '23892479587815260433', 'videoObjectPageProps': {'videoProps': {'url': 'https://www.tiktok.com/#alanwalkermusic/video/6816594007829859589', 'name': 'Alan Walker(#alanwalkermusic) on TikTok I’m that friend who can’t stand still when taking photos', 'description': 'Alan Walker(#alanwalkermusic) has created a short video on TikTok with music Heading Home. I’m that friend who can’t stand still when taking photos', 'keywords': 'alanwalkermusic, Alan Walker,', 'thumbnailUrl': ['https://p16-va-default.akamaized.net/obj/tos-maliva-p-0068/8187e5fe9a0f684529910363f5dbe428', 'https://p16-va-default.akamaized.net/obj/tos-maliva-p-0068/7dd18717d8aa4916abc5699c25c09b3e_1587111976'], 'uploadDate': '2020-04-17T08:26:14.000Z', 'contentUrl': 'https://v19.muscdn.com/afefda4362dccd13b93a4d8e79ab5338/5ea477c7/video/tos/useast2a/tos-useast2a-ve-0068c004/7f922f16b9534b80be6523cbb8ba2ce2/?a=1233&br=2652&bt=1326&cr=0&cs=0&dr=0&ds=3&er=&l=202004251147400101150770371E5160EE&lr=tiktok_m&qs=0&rc=MzY3cXc1OjxwdDMzNjczM0ApNDtnNTY1Ojw2N2k8NDU4ZWdoZXBmLjE0ZGBfLS0vMTZzczZjYDEvL2BgMDAzXy0uMC86Yw%3D%3D&vl=&vr=', 'embedUrl': 'https://www.tiktok.com/embed/v2/6816594007829859589', 'commentCount': '300', 'duration': 'PT11S', 'audio': {'name': 'Heading Home - Alan Walker, Ruben', 'author': 'Alan Walker, Ruben', 'mainEntityOfPage': {'#type': 'ItemPage', '#id': 'https://www.tiktok.com/music/Heading-Home-6805465027164768258'}}, 'creator': {'#type': 'Person', 'name': 'Alan Walker', 'alternateName': 'alanwalkermusic', 'url': 'https://www.tiktok.com/#alanwalkermusic', 'interactionStatistic': [{'#type': 'InteractionCounter', 'interactionType': {'#type': 'http://schema.org/LikeAction'}, 'userInteractionCount': '10903873'}, {'#type': 'InteractionCounter', 'interactionType': {'#type': 'http://schema.org/FollowAction'}, 'userInteractionCount': 2147815}]}, 'width': 540, 'height': 960, 'interactionStatistic': [{'#type': 'InteractionCounter', 'interactionType': {'#type': 'http://schema.org/WatchAction'}, 'userInteractionCount': 91447}, {'#type': 'InteractionCounter', 'interactionType': {'#type': 'http://schema.org/LikeAction'}, 'userInteractionCount': 14145}, {'#type': 'InteractionCounter', 'interactionType': {'#type': 'http://schema.org/ShareAction'}, 'userInteractionCount': 29}]}, 'pageProps': {'type': 'ItemPage', 'id': 'https://www.tiktok.com/#alanwalkermusic/video/6816594007829859589'}, 'breadcrumbProps': {'urlList': [{'name': 'TikTok', 'url': 'https://www.tiktok.com'}, {'name': 'Alan Walker(#alanwalkermusic) Official | TikTok', 'url': 'https://www.tiktok.com/#alanwalkermusic'}, {'name': 'Alan Walker(#alanwalkermusic) on TikTok I’m that friend who can’t stand still when taking photos', 'url': 'https://www.tiktok.com/#alanwalkermusic/video/6816594007829859589'}]}}, 'metaParams': {'title': 'Alan Walker(#alanwalkermusic) on TikTok I’m that friend who can’t stand still when taking photos', 'keywords': 'alanwalkermusic, Alan Walker,', 'description': 'Alan Walker(#alanwalkermusic) has created a short video on TikTok with music Heading Home. I’m that friend who can’t stand still when taking photos', 'robotsContent': 'index, follow'}, 'isSSR': True, 'pageOptions': {'header': {'showUpload': True, 'type': 'webapp'}, 'headOptions': None}}, 'pathname': '/share/video'}, 'page': '/share/video', 'query': {'uniqueId': 'alanwalkermusic', 'id': '6816594007829859589', '$initialProps': {'$wid': '6819614602332063233'}, 'webtoken': 'tac=\'i+2gv2ay5eehis!i#piis"yZl!%s"l"u&kLs#l l#vr*charCodeAtx0[!cb^i$1em7b*0d#>>>s j\\uffeel s#0y\\xe8g,&qnfme|ms l vk.}l ,(dfijxdaamvk5}l ,(dfijxdaam,$lwcamk\\xadl ,(dfijxdaam,$lwcams!l!v,\\\'nfmosCkmx,*~bgyad>r}~[!c0b<k$t jql!v,\\\'nfmosCkmx,%cokm3[!c0d#===k$t jMl!v,\\\'nfmosCkmx,0xefc.:9&*.4+2-0.[!c0d#===k"t f z[ cb|1d<y\\u01ea,(|fY\\x7f~d`hs g,(lfi~ah`{ms!g,&qnfme|ms"g,)gk}ejo{\\x7fcms#,)|doikgauus$ul"d\\\',typeofl$d#===v!kA}l"vl mx[ c,/T\\x7fsxvwa6#qw~tk#d#!==v!k\\\\}gr&Object,)yxdxbzv`tml mvr$callxl"[!c,/T\\x7fsxvwa6#qw~tk#d#!==v!k4}ul!d\\\',typeofl$d#===v!kG}l!vl mx[ cv,\\\'nfmosCkmx,(Lfi~ah`{[!c0b<v!k4}ul#d\\\',typeofl$d#===v!kD}l#vl mx[ c,2I|v\\x7fstl9Tzjty~TNP~d#!==v!k=}ugr(locationd\\\',typeofl$d#===k"t fv!k4}l!,,hbmz}t|gYzrrm!!!kjg,\\\'oaz~d~tms%ul%d\\\',typeofl$d#===v!kB}l%vl mx[ c,0K~pyqvb7PpiosogBd#!==k"t f z[ cb|1d<y\\xe2g,&qnfme|ms l vk-}l ,\\\'dggyd`hmvk7}l ,\\\'dggyd`hm,\\\'aa{oiyjmk"t ugr.InstallTriggerd\\\',typeof,)|doikgauud#!==kwl vkn}l ,*e~xh|Xyuf{ml ,*cebh|Xyuf{mb-\\x94b>v!kF}l ,+dyyk}Xt{t|aml ,+bbck}Xt{t|amb-\\x94b>k"t f z[ cb|1d<y\\xa0g,&akgkkgms g,&Iebli\\x7fms!ul d\\\',typeof,)|doikgauud#!==vkh}l!,)yxdxbzv`tm,(|fY\\x7f~d`hmvr$callxl ,\\\'wzfin\\x7f~m[!c,0K~pyqvb7hkuxynmBd#=== z[ cb|1d<y\\u011eg,(lfi~ah`{ms g,)gk}ejo{\\x7fcms!g,&qnfme|ms"fv!k4}l ,,hbmz}t|gYzrrm!!!k\\xd7,\\\'wd|mbb~l!d"in!v!kI}l!,\\\'wd|mbb~mg,+[`xif~P`aulmd*instanceof!v!k1},(Wybjbyabl"d"inv!k4},+hmab_xp|g{xl"d"inv!k4},+TScghxe\\x7frfpl"d"inv!kP},%Dscafl"d"in,8[xtm}nLzNEGQMKAdGG^NTY\\x1ckl"d"inb< f z[ cb|1d<y\\u02a1g,&qnfme|ms g,)gk}ejo{\\x7fcms!g,&Iebli\\x7fms"l!,)~oih\\x7fgyucmk"t (\\x80,.jjvx|vDgyg}knbl"d"inkfl"v,.jjvx|vDgyg}knbmxl!,)~oih\\x7fgyucgr&Objectn vuq%valuevfq(writable[#c}) %{s#t ,4KJarz}hrjxl#EWCOQDRB,3LKfs{}wsnqB{iAMWBP#,;DCj{}DSKUAWyTK[C[XrHZ^RFZ[[,7HGn\\x7fyxowiES}PGWOW\\\\vL^BN,5JI`}{~iuk{m\\x7fRAQMURxNG,3LKsnsjpl~nB{iAMWBP#,2MLpg\\x7fa}kEnrjl~PQGG,5JI`}{~iuk{m\\x7fTLTVDVWMM,1NMwf|`rjF\\x7fm}qk~TD,4KJert|tripAjNVPBTUCC,4KJpo|ksmyoAjNVPBTUCC[+s#,)Vyn`h`fe|,,olbcCt~vz|cz,6ID}u\\x7fuuhs#ieg|v#EHZMOY[#s$l$*%s%l%u&k4s&l$l&ms\\\'l l\\\'mk"t j\\x06l#*%s%l%u&k?s&l#l&ms\\\'l ,(lfi~ah`{ml\\\'mk"t j\\ufffbl ,(lfi~ah`{m*%s%l%u&kls&l&vr%matchxgr&RegExp$*\\\\$[a-z]dc_$ n"[!cvk:}l ,(lfi~ah`{ml&m,&efkaoTmk"t j\\uffcef z[ cb|1d<y\\u024fg,&qnfme|ms gr&RegExp$+constructor$!in"vr$testxl ,+CX#BJ|t\\x7fvzam[!cv!k\\xb2}yZl vr(toStringx[ c,AzMAN#ES\\x08zKMM_G}U\\\\]GQ{YCQ_SX]IWP.\\x1cd#=== l ,&ufnhxbm!v!kd}ugr&safarid\\\',typeof,)|doikgauud#!==vk=}gr&safari,0`da{Zzb~~pyzhtqqm&k\\u010e(=l v,,c}kaTpfrvtermxzzzz[$c}) %{s!t (\\x85l ,.}jcb{|zFbxjx}~mvr\\\'setItemx,+xc`kDuhZvfp, ["c}l ,.}jcb{|zFbxjx}~mvr*removeItemx,+xc`kDuhZvfp[!c}) \\x7f{s!l!,$gjbbmgr,DOMException,2CF[AWH]AY^YY[[\\x7fdpqmd#===vkC}l ,.}jcb{|zFbxjx}~m,&jbfn~cm0d#===k"t f fv!k>}g,(lfi~ah`{m,,hbmz}t|gYzrrm!!k`l ,)`doiukkTSm!vkJ}l ,,\\\\bgadt`Vbpxcmv!k4}l ,.C\\\\#~{}`pdRn|tomk"t f z[ cb|1d<y\\u0165g,(lfi~ah`{ms g,)gk}ejo{\\x7fcms!,(|fY\\x7f~d`hs",\\\'nfmosCks#fv!k4}l ,,hbmz}t|gYzrrm!!!k\\u0113l v,-n|jqewVxp{rvmmx,&eff\\x7fkx[!cs$l$,)}eOmyoZB]mvl"mx[ cv,\\\'umyfjohmxgr&RegExp$#\\\\s*$!gn"$ ["cvl#mx,*djxdxjs~vv[!c0b<v!kh}l!l"mvl"mx[ cvr\\\'replacexgr&RegExp$#\\\\s*$!gn"$ ["cvl#mx,*djxdxjs~vv[!c0b<v!kP}l!,\\\'wd|mbb~mvl"mx[ c,4Ozt}}zn;LqkxIOcQVD_zd#!== f z[ cb|1d<1b|\'', '0fea6a13c52b4d4725368f24b045ca84': {}, 'aa59d67c2123f094d0d6798ffe651c4d': {}}, 'buildId': '1.0.1.1363', 'assetPrefix': '//s16.tiktokcdn.com/tiktok/falcon', 'isFallback': False, 'customServer': True}
I can reach any values by writing so:
import json
parsed = json.loads(source_code)
props = parsed['props']['pageProps']['videoData']
follower = props['authorStats']['followerCount']
heartcount = props['authorStats']['heartCount']
AuthorID = props['itemInfos']['authorId']
Commentcount = pandas.DataFrame(props['itemInfos']['commentCount']
CreateTime = props['itemInfos']['createTime']
But I was not able to put all of them into a dataframe with one row and all of those follower,heartcount etc as columns.
Thank you for your help!
This question already has answers here:
How can I convert JSON to CSV?
(26 answers)
Closed 3 years ago.
I am trying to write my JSON output to CSV, but I'm not sure how to separate my values into individual columns
This is my current code
with open('dict.csv', 'w') as csv_file:
writer = csv.writer(csv_file)
for key, value in response.json().items():
writer.writerow([value])
print(value)
This is the csv file I am getting:
current csv file
This is the desired csv file/output I want to get:
desired output
This is an example of my JSON Output
[{'id': '123', 'custom_id': '12', 'company': 28, 'company_name': 'Sunshine'}, {'id': '224', 'custom_id': '14', 'company': 38, 'company_name': 'Flowers'},
{'id': '888', 'custom_id': '10', 'company': 99, 'company_name': 'Fields'}]
how about this JSON format? (a more complicated one)
[{'id': '777', 'custom_id': '000112', 'company': 28, 'company_name':
'Weddings Inc', 'delivery_address': '25 olive park terrace, 61234', 'delivery_timeslot': {'lower': '2019-12-06T10:00:00Z', 'upper': '2019-12-06T13:00:00Z', 'bounds': '[)'}, 'sender_name': 'Joline', 'sender_email': '', 'sender_contact': '91234567', 'removed': None, 'recipient_name': 'Joline', 'recipient_contact': '91866655', 'notes': '', 'items': [{'id': 21668, 'name': 'Loose hair flowers', 'quantity': 1, 'metadata': {}, 'removed': None}, {'id': 21667, 'name': "Groom's Boutonniere", 'quantity': 1, 'metadata': {}, 'removed': None}, {'id': 21666, 'name': 'Bridal Bouquet', 'quantity': 1, 'metadata': {}, 'removed': None}], 'latitude': '1.1234550920764211111', 'longitude': '103.864352476201000000', 'created': '2019-08-15T05:40:30.385467Z', 'updated': '2019-08-15T05:41:27.930110Z', 'status': 'pending', 'verbose_status': 'Pending', 'logs': [{'id': 56363, 'order': '50c402', 'order_custom_id': '000112', 'order_delivery_address': '25 olive park terrace, 61234', 'order_delivery_timeslot': {'lower': '2019-12-06T10:00:00Z', 'upper': '2019-12-06T13:00:00Z', 'bounds': '[)'}, 'message': 'Order was created.', 'failure_reason': None, 'success_code': None, 'success_description': None, 'created': '2019-08-15T05:40:30.431790Z', 'removed': None}, {'id': 56364, 'order': '50c402d8-7c76-45b5-b883-e2fb887a507e', 'order_custom_id': 'INV-000112', 'order_delivery_address': '25 olive park terrace, 61234', 'order_delivery_timeslot': {'lower': '2019-12-06T10:00:00Z', 'upper': '2019-12-06T13:00:00Z', 'bounds': '[)'}, 'message': 'Order is pending.', 'failure_reason': None, 'success_code': None, 'success_description': None, 'created': '2019-08-15T05:40:30.433139Z', 'removed': None}], 'reschedule_requests': [], 'signature': None},
{'id': '241', 'custom_id': '000123', 'company': 22, 'company_name': 'Pearl Pte Ltd', 'delivery_address': '90 Merchant Road, Hotel Royal, 223344', 'delivery_timeslot': {'lower': '2019-11-29T10:00:00Z', 'upper': '2019-11-29T13:00:00Z', 'bounds': '[)'}, 'sender_name': 'Vera Smith', 'sender_email': '', 'sender_contact': '81234567', 'removed': None, 'recipient_name': 'Vera Smith', 'recipient_contact': '81234561', 'notes': '', 'items': [{'id': 22975, 'name': 'Custom wrapped bouquet', 'quantity': 2, 'metadata': {}, 'removed': None}, {'id': 22974, 'name': "Parents' boutonniere x 3", 'quantity': 1, 'metadata': {}, 'removed': None}, {'id': 22973, 'name': "Groom's boutonniere", 'quantity': 1, 'metadata': {}, 'removed': None}, {'id': 22972, 'name': 'Loose hair flowers', 'quantity': 1, 'metadata': {}, 'removed': None}, {'id': 22971, 'name': 'Bridal Bouquet', 'quantity': 1, 'metadata': {}, 'removed': None}], 'latitude': '1.28821802835873000000', 'longitude': '103.84569230314800000000', 'created': '2019-08-30T03:20:17.477528Z', 'updated': '2019-08-30T03:29:25.307856Z', 'status': 'pending', 'verbose_status': 'Pending', 'logs': [{'id': 59847, 'order': '24117085-9104-4442-841b-4a734f801d39', 'order_custom_id': 'INV-000123', 'order_delivery_address': '90 Merchant Road, Hotel Royal, 223344', 'order_delivery_timeslot': {'lower': '2019-11-29T10:00:00Z', 'upper': '2019-11-29T13:00:00Z', 'bounds': '[)'}, 'message': 'Order was created.', 'failure_reason': None, 'success_code': None, 'success_description': None, 'created': '2019-08-30T03:20:17.511250Z', 'removed': None}, {'id': 59848, 'order': '24117085-9104-4442-841b-4a734f801d39', 'order_custom_id': 'INV-000123', 'order_delivery_address': '90 Merchant Road, Hotel Royal, 223344', 'order_delivery_timeslot': {'lower': '2019-11-29T10:00:00Z', 'upper': '2019-11-29T13:00:00Z', 'bounds': '[)'}, 'message': 'Order is pending.', 'failure_reason': None, 'success_code': None, 'success_description': None, 'created': '2019-08-30T03:20:17.513132Z', 'removed': None}], 'reschedule_requests': [], 'signature': None}]
Use pandas library:
df.to_csv() - Write object to a comma-separated values (csv) file.
Ex.
import pandas as pd
data = [{'id': '123', 'custom_id': '12', 'company': 28, 'company_name': 'Sunshine'},
{'id': '224', 'custom_id': '14', 'company': 38, 'company_name': 'Flowers'},
{'id': '888', 'custom_id': '10', 'company': 99, 'company_name': 'Fields'}]
df = pd.DataFrame(data)
df.to_csv('sample.csv')
Try:
import csv
csv_file = 'my_file.csv'
csv_columns = ['id', 'custom_id', 'company', 'company_name']
dict_data = [{'id': '123', 'custom_id': '12', 'company': 28, 'company_name': 'Sunshine'}, {'id': '224', 'custom_id': '14', 'company': 38, 'company_name': 'Flowers'}, {'id': '888', 'custom_id': '10', 'company': 99, 'company_name': 'Fields'}]
try:
with open(csv_file, 'w') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
writer.writeheader()
for data in dict_data:
writer.writerow(data)
except IOError:
print("I/O error")
Given your response data in json format
response = [{'id': '123', 'custom_id': '12', 'company': 28, 'company_name': 'Sunshine'},
{'id': '224', 'custom_id': '14', 'company': 38, 'company_name': 'Flowers'},
{'id': '888', 'custom_id': '10', 'company': 99, 'company_name': 'Fields'}]
You can convert it to a list of lists using
header = [response[0].keys()]
data = [row.values() for row in response]
csv_list = header + data
And then save it to csv using
with open('dict.csv', "w") as f:
for row in csv_list:
f.write("%s\n" % ','.join(str(col) for col in row))
This should yield your desired output
I'm confused. None of the stuff I tried from other related questions worked and I can't seem to find it by googling.
I want to filter a json api response with Python, without just sorting the datafeed I get back - that's not much good to me. I also want to explicitly select one field, rather than deleting all the other fields, because sometimes there are more fields than other times. It has to be accomplished with the structure of the request, not by modifying anything after the fact.
I use the following code to get a list of sports from the matchbook api, but how would I just show the names of those sports, filtering out the id and types?
r7 = s.get('https://api.matchbook.com/edge/rest/lookups/sports')
r8 = r7.json()
pprint.pprint (r8)
This is what I get back:
{'offset': 0,
'per-page': 20,
'sports': [{'id': 112, 'name': 'Australian Rules', 'type': 'SPORT'},
{'id': 13, 'name': 'Auto Racing', 'type': 'SPORT'},
{'id': 3, 'name': 'Baseball', 'type': 'SPORT'},
{'id': 4, 'name': 'Basketball', 'type': 'SPORT'},
{'id': 14, 'name': 'Boxing', 'type': 'SPORT'},
{'id': 110, 'name': 'Cricket', 'type': 'SPORT'},
{'id': 11, 'name': 'Current Events', 'type': 'SPORT'},
{'id': 115, 'name': 'Cycling', 'type': 'SPORT'},
{'id': 116, 'name': 'Darts', 'type': 'SPORT'},
{'id': 117, 'name': 'Gaelic Football', 'type': 'SPORT'},
{'id': 8, 'name': 'Golf', 'type': 'SPORT'},
{'id': 241798357140019,
'name': 'Greyhound Racing',
'type': 'SPORT'},
{'id': 24735152712200, 'name': 'Horse Racing', 'type': 'SPORT'},
{'id': 222109340250019,
'name': 'Horse Racing (Ante Post)',
'type': 'SPORT'},
{'id': 231138347942400,
'name': 'Horse Racing Beta',
'type': 'SPORT'},
{'id': 118, 'name': 'Hurling', 'type': 'SPORT'},
{'id': 6, 'name': 'Ice Hockey', 'type': 'SPORT'},
{'id': 126, 'name': 'MMA', 'type': 'SPORT'},
{'id': 5, 'name': 'NCAA Basketball', 'type': 'SPORT'},
{'id': 2, 'name': 'NCAA Football', 'type': 'SPORT'}],
'total': 28}
401
[Finished in 5.3s]
How would I get rid of the 'id' and 'type' fields?
This is an extract of a large set of json data:
{'events': [{'allow-live-betting': True,
'category-id': [9,
297063445660036,
410444698700010,
410468520880009,
477274740480010,
486941505790009],
'id': 488243069570009,
'in-running-flag': True,
'markets': [{'allow-live-betting': True,
'back-overround': 102.04249,
'event-id': 488243069570009,
'id': 488243069830010,
'in-running-flag': True,
'lay-overround': 97.95751,
'live': True,
'market-type': 'money_line',
'name': 'Moneyline',
'runners': [{'event-id': 488243069570009,
'event-participant-id': 488243069720009,
'id': 488243069860009,
'market-id': 488243069830010,
'name': 'G Mager',
'prices': [{'available-amount': 48.42639,
'currency': 'GBP',
'decimal-odds': 1.53191,
'exchange-type': 'back-lay',
'odds': 1.53191,
'odds-type': 'DECIMAL',
'side': 'back'},
{'available-amount': 473.49579,
'currency': 'GBP',
'decimal-odds': 1.51546,
'exchange-type': 'back-lay',
'odds': 1.51546,
'odds-type': 'DECIMAL',
'side': 'back'},
{'available-amount': 96.87754,
'currency': 'GBP',
'decimal-odds': 1.40322,
'exchange-type': 'back-lay',
'odds': 1.40322,
'odds-type': 'DECIMAL',
'side': 'back'},
{'available-amount': 710.74,
'currency': 'GBP',
'decimal-odds': 1.5814,
'exchange-type': 'back-lay',
'odds': 1.5814,
'odds-type': 'DECIMAL',
'side': 'lay'},
{'available-amount': 163.74192,
'currency': 'GBP',
'decimal-odds': 1.76336,
'exchange-type': 'back-lay',
'odds': 1.76336,
'odds-type': 'DECIMAL',
'side': 'lay'},
{'available-amount': 151.55072,
'currency': 'GBP',
'decimal-odds': 1.9434,
'exchange-type': 'back-lay',
'odds': 1.9434,
'odds-type': 'DECIMAL',
'side': 'lay'}],
'status': 'open',
'volume': 6955.72965},
{'event-id': 488243069570009,
'event-participant-id': 488243069660010,
'id': 488243069890010,
'market-id': 488243069830010,
'name': 'A Bedene',
'prices': [{'available-amount': 413.22093,
'currency': 'GBP',
'decimal-odds': 2.72,
'exchange-type': 'back-lay',
'odds': 2.72,
'odds-type': 'DECIMAL',
'side': 'back'},
{'available-amount': 124.99383,
'currency': 'GBP',
'decimal-odds': 2.31,
'exchange-type': 'back-lay',
'odds': 2.31,
'odds-type': 'DECIMAL',
'side': 'back'},
{'available-amount': 142.97238,
'currency': 'GBP',
'decimal-odds': 2.06,
'exchange-type': 'back-lay',
'odds': 2.06,
'odds-type': 'DECIMAL',
'side': 'back'},
{'available-amount': 25.75872,
'currency': 'GBP',
'decimal-odds': 2.88,
'exchange-type': 'back-lay',
'odds': 2.88,
'odds-type': 'DECIMAL',
'side': 'lay'},
{'available-amount': 244.07,
'currency': 'GBP',
'decimal-odds': 2.94,
'exchange-type': 'back-lay',
'odds': 2.94,
'odds-type': 'DECIMAL',
'side': 'lay'},
{'available-amount': 39.06352,
'currency': 'GBP',
'decimal-odds': 3.48,
'exchange-type': 'back-lay',
'odds': 3.48,
'odds-type': 'DECIMAL',
'side': 'lay'}],
'status': 'open',
'volume': 16033.12548}],
'start': '2017-05-15T11:05:00.000Z',
'status': 'open',
'type': 'binary',
'volume': 22988.85514}],
'meta-tags': [{'id': 9,
'name': 'Tennis',
'type': 'SPORT',
'url-name': 'tennis'},
{'id': 297063445660036,
'name': 'R1',
'type': 'DATE',
'url-name': 'r1'},
{'id': 410444698700010,
'name': 'Italy',
'type': 'COUNTRY',
'url-name': 'italy'},
{'id': 410468520880009,
'name': 'Live Betting',
'type': 'OTHER',
'url-name': 'live-betting'},
{'id': 477274740480010,
'name': 'May 15th 2017',
'type': 'DATE',
'url-name': 'may-15th-2017'},
{'id': 486941505790009,
'name': 'ATP Rome',
'type': 'COMPETITION',
'url-name': 'ATP-Rome'}],
'name': 'G Mager vs A Bedene',
'sport-id': 9,
'start': '2017-05-15T11:05:00.000Z',
'status': 'open',
'volume': 23098.72333},
'offset': 0,
'per-page': 20,
'total': 223}
I want to find the event-id within this data and print "'event-id': 488243069570009"
I managed to do this with:
r11 = s.get('https://api.matchbook.com/edge/rest/events')
r12 = r11.json()
for each in r12['events'][0]['markets']:
print(each['event-id'])
but it only prints the first event-id on the complete set of json data
You can simply create a new array using shorthand
data = {"offset":0,"per-page":20,"sports":[{"id":112,"name":"Australian Rules","type":"SPORT"},{"id":13,"name":"Auto Racing","type":"SPORT"},{"id":3,"name":"Baseball","type":"SPORT"},{"id":4,"name":"Basketball","type":"SPORT"},{"id":14,"name":"Boxing","type":"SPORT"},{"id":110,"name":"Cricket","type":"SPORT"},{"id":11,"name":"Current Events","type":"SPORT"},{"id":115,"name":"Cycling","type":"SPORT"},{"id":116,"name":"Darts","type":"SPORT"},{"id":117,"name":"Gaelic Football","type":"SPORT"},{"id":8,"name":"Golf","type":"SPORT"},{"id":241798357140019,"name":"Greyhound Racing","type":"SPORT"},{"id":24735152712200,"name":"Horse Racing","type":"SPORT"},{"id":222109340250019,"name":"Horse Racing (Ante Post)","type":"SPORT"},{"id":231138347942400,"name":"Horse Racing Beta","type":"SPORT"},{"id":118,"name":"Hurling","type":"SPORT"},{"id":6,"name":"Ice Hockey","type":"SPORT"},{"id":126,"name":"MMA","type":"SPORT"},{"id":5,"name":"NCAA Basketball","type":"SPORT"},{"id":2,"name":"NCAA Football","type":"SPORT"}],"total":28}
# print(data['sports'])
# for element in data['sports']:
# del element['id']
# del element['type']
# print(data['sports'])
new_arr = [_['name'] for _ in data['sports']];
print(new_arr)
UPDATE
Check the online demo
You can't do what you're asking the way you're asking. The matchbook API just doesn't work like that.
You could do something silly, like add a proxy server in between you and their API that does the filtering for you, so you aren't the one doing the filtering, it's the proxy, but that's just playing with the semantics.
Agam Banga's example does exactly what you stated you want:
how would I just show the names of those sports, filtering out the id and types?
Here's a full example that you can literally copy, paste, and run, and it will print out all the sports that matchbook supports:
import requests
r = requests.get('https://api.matchbook.com/edge/rest/lookups/sports')
names = [_['name'] for _ in r.json()['sports']]
for name in names:
print('Sport Name:', name)
I ran it, and here's what it output:
Sport Name: Australian Rules
Sport Name: Auto Racing
Sport Name: Baseball
Sport Name: Basketball
Sport Name: Boxing
Sport Name: Cricket
Sport Name: Current Events
Sport Name: Cycling
Sport Name: Darts
Sport Name: Gaelic Football
Sport Name: Golf
Sport Name: Greyhound Racing
Sport Name: Horse Racing
Sport Name: Horse Racing (Ante Post)
Sport Name: Horse Racing Beta
Sport Name: Hurling
Sport Name: Ice Hockey
Sport Name: MMA
Sport Name: NCAA Basketball
Sport Name: NCAA Football