如何处理嵌套的json重复条目并将其保存在csv中的新行中?

deikduxw  于 2022-12-06  发布在  其他
关注(0)|答案(1)|浏览(146)

我正在尝试将API响应转换为csv文件。
我面临什么问题??
查看下面所附json中的filesdescriptions字段。
在API响应中,这些数组可以有任意数量的条目,如示例json中所示。
我想达到什么目的?
我想要一个csv文件,其中有如下列。
idimg1img2、...(所有图像)...、Market DescriptionAssociated Comments、...(所有说明)...

  • 此处,img1、img2等位于fileslinksurl中 *

  • 用于说明... discriptions . type的值应为列名。discriptions . discription应为相应列中的值。*

我试着使用json_normalize,但是,由于这些filesdescriptions数组是随机长度的,我完全不知道如何处理。
请帮我解决这个问题。谢谢你给我宝贵的时间。任何帮助或指导对我来说都是有价值的。
还有,如果你们有其他方法或者其他能帮到我的方法,请告诉我.

API响应::

"data": [
        {
            "id": "35776",
            "type": "ProductData",
            "files": [
                {
                    "id": "2894907",
                    "type": "Image",
                    "file_extension": "JPG",
                    "media_content": "Photo - Primary",
                    "generic": true,
                    "links": [
                        {
                            "url": "https://d32vzsop7y1h3k.cloudfront.net/cc3a35729a75a8510c4a0b14a7fc6fd4.JPG",
                            "height": "1070.00",
                            "width": "800.00",
                            "size": "L"
                        }
                    ]
                },
                {
                    "id": "6196485",
                    "type": "Image",
                    "file_extension": "JPG",
                    "media_content": "Photo - Primary",
                    "generic": true,
                    "links": [
                        {
                            "url": "https://d32vzsop7y1h3k.cloudfront.net/b8c7fa80b5e6fc9d35e2a8c8ee59e9ef.JPG",
                            "height": "570.00",
                            "width": "800.00",
                            "size": "L"
                        }
                    ]
                },
                {
                    "id": "7079630",
                    "type": "Image",
                    "file_extension": "JPG",
                    "media_content": "Photo - Primary",
                    "generic": true,
                    "links": [
                        {
                            "url": "https://d32vzsop7y1h3k.cloudfront.net/7c39c695853f4a51ff1fe957cc4b2103.JPG",
                            "height": "533.00",
                            "width": "800.00",
                            "size": "L"
                        }
                    ]
                },
                {
                    "id": "13400593",
                    "type": "Image",
                    "file_extension": "JPG",
                    "media_content": "Photo - Primary",
                    "generic": true,
                    "links": [
                        {
                            "url": "https://d32vzsop7y1h3k.cloudfront.net/95f42ba54e4106298efb5e84955e91a9.JPG",
                            "height": "800.00",
                            "width": "800.00",
                            "size": "L"
                        }
                    ]
                },
                {
                    "id": "23536454",
                    "type": "Image",
                    "file_extension": "JPG",
                    "media_content": "Photo - Primary",
                    "generic": true,
                    "links": [
                        {
                            "url": "https://d32vzsop7y1h3k.cloudfront.net/9ef4515f90311a25e69f87111bee03f9.JPG",
                            "height": "800.00",
                            "width": "800.00",
                            "size": "L"
                        }
                    ]
                },
                {
                    "id": "7079629",
                    "type": "Image",
                    "file_extension": "PNG",
                    "media_content": "Logo Image",
                    "generic": true,
                    "links": [
                        {
                            "url": "https://d32vzsop7y1h3k.cloudfront.net/b2e60a9f192a7032e8b87b966c826187.PNG",
                            "height": "390.00",
                            "width": "800.00",
                            "size": "L"
                        }
                    ]
                },
                {
                    "id": "13400592",
                    "type": "Image",
                    "file_extension": "JPG",
                    "media_content": "Logo Image",
                    "generic": true,
                    "links": [
                        {
                            "url": "https://d32vzsop7y1h3k.cloudfront.net/99b17aa8393a06019fea7b4bb1b58727.JPG",
                            "height": "417.00",
                            "width": "800.00",
                            "size": "L"
                        }
                    ]
                }
            ],
            "descriptions": [
                {
                    "type": "Market Description",
                    "description": "All EBC rotors are made from OE spec grey cast iron, exactly as used on new car production and as many as we have tools for are BRITISH MADE wholly in our own UK foundry. Currently EVERY SINGLE ROTOR sold in Europe and the UK is BRITISH MADE and a majority of the designs specific to the USA are also BRITISH made.The British foundry is constantly expanding its in house tooled range but EBC like every brake manufacturer ....does need occasionally to buy some rotors in from approved sources to complete ranges in overseas markets. None of our competitors will ever tell you where their rotors come from and we at EBC are as disappointed as the rest of the world that cost pressure means there is not ONE foundry left in the USA to supply such parts, other brake brands when asked about origin will just sidestep the question. When we do buy rotors in, they are specified, sampled, tested for element analysis, grain structure, tensile strength, hardness and optimum ductility and tested 100 piece by piece to be perfect for runout on this in house machine."
                },
                {
                    "type": "Associated Comments",
                    "description": "DO NOT FIT UPGRADE PADS TO REAR OF VEHICLE UNLESS SAME UPGRADE FITTED TO FRONT, The ?Thermic Black coating? does NOT need to be removed before install. Do NOT use brake cleaner or any other method to remove Thermic Black coating from discs rotors. The Thermic black coating will be removed in the pad swept area by the brake pads with in the first 10 to 20 stops made after installation on the vehicle.The ?Thermic Black coating? is an anti corrosion coating for long resistance against rust. Attempting to remove Thermic Black Coating with brake cleaner or any other method is NOT covered under EBC warranty"
                },
                {
                    "type": "Associated Comments",
                    "description": "DO NOT FIT UPGRADE PADS TO REAR OF VEHICLE UNLESS SAME UPGRADE FITTED TO FRONT, The Thermic Black coating? does NOT need to be removed before install. Do NOT use brake cleaner or any other method to remove Thermic Black coating from discs rotors. The Thermic black coating will be removed in the pad swept area by the brake pads with in the first 10 to 20 stops made after installation on the vehicle.The Thermic Black coating? is an anti corrosion coating for long resistance against rust. Attempting to remove Thermic Black Coating with brake cleaner or any other method is NOT covered under EBC warranty"
                },
                {
                    "type": "Product Description - Extended",
                    "description": "EBC's GD sport rotors features wide aperture slots for cooling to reduce temperatures preventing brake fade. Dimple drilling avoids stress cracks with Thermic black finish with a sleek look whilst preventing corrosion."
                },
                {
                    "type": "Market Description",
                    "description": "Feature wider slots and blind drilled dimples to avoid cracks, these degas pads and remove dirt dust and debris from braking area"
                },
                {
                    "type": "Product Description - Extended",
                    "description": "EBC 3GD Series Sport Slotted Rotors; Rear; 11.1 in. Dia.; Set of Two;"
                },
                {
                    "type": "Product Description - Short",
                    "description": "EBC 09-14 Acura TSX 2.4 GD Sport Rear Rotors"
                },
                {
                    "type": "Application Summary",
                    "description": "2004 thru 2005 HONDA Accord Sedan 3.0 Hybrid"
                },
                {
                    "type": "Application Summary",
                    "description": "2006 thru 2007 HONDA Accord Sedan 3.0 Hybrid"
                },
                {
                    "type": "Application Summary",
                    "description": "2013 thru 2016 HONDA Accord Sedan 2.0 hybrid"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Sedan 3.5 Touring"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Coupe 3.5 Touring"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Sedan 2.0 hybrid"
                },
                {
                    "type": "Product Description - Long",
                    "description": "GD Rotors REAR Disc Brake Rotor FMSI D537"
                },
                {
                    "type": "Application Summary",
                    "description": "2007 thru 2012 HONDA Accord Sedan 2.4 EX"
                },
                {
                    "type": "Application Summary",
                    "description": "2008 thru 2012 HONDA Accord Sedan 2.4 LX"
                },
                {
                    "type": "Application Summary",
                    "description": "2013 thru 2015 HONDA Accord Sedan 2.4 LX"
                },
                {
                    "type": "Application Summary",
                    "description": "2013 thru 2015 HONDA Accord Sedan 2.4 EX"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Sedan 2.4 Sport"
                },
                {
                    "type": "Application Summary",
                    "description": "2008 thru 2012 HONDA Accord Coupe 2.4 EX"
                },
                {
                    "type": "Application Summary",
                    "description": "2008 thru 2012 HONDA Accord Coupe 2.4 LX"
                },
                {
                    "type": "Application Summary",
                    "description": "2013 thru 2015 HONDA Accord Coupe 2.4 LX"
                },
                {
                    "type": "Application Summary",
                    "description": "2013 thru 2015 HONDA Accord Coupe 2.4 EX"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Coupe 2.4 LX-S"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Coupe 3.5 EX-L"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Sedan 2.4 EX-L"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Coupe 2.4 EX-L"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Sedan 3.5 EX-L"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Coupe 2.4 EX"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Sedan 2.4 EX"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 and up HONDA Accord Sedan 2.4 LX"
                },
                {
                    "type": "Application Summary",
                    "description": "2008 thru 2012 HONDA Accord Sedan 3.5"
                },
                {
                    "type": "Application Summary",
                    "description": "2013 thru 2015 HONDA Accord Sedan 3.5"
                },
                {
                    "type": "Application Summary",
                    "description": "2008 thru 2012 HONDA Accord Coupe 3.5"
                },
                {
                    "type": "Application Summary",
                    "description": "2013 thru 2015 HONDA Accord Coupe 3.5"
                },
                {
                    "type": "Product Description - Invoice",
                    "description": "GD7440 REAR GD Pattern Rotors"
                },
                {
                    "type": "Application Summary",
                    "description": "2009 thru 2014 ACURA TSX 2.4"
                },
                {
                    "type": "Application Summary",
                    "description": "2010 thru 2014 ACURA TSX 3.5"
                },
                {
                    "type": "Application Summary",
                    "description": "2015 and up HONDA HR-V 1.8"
                },
                {
                    "type": "Application Summary",
                    "description": "2017 and up ACURA ILX 2.4"
                },
                {
                    "type": "Product Description - Long",
                    "description": "EBC GD SPORT ROTOR KIT"
                },
                {
                    "type": "Product Description - Short",
                    "description": "EBC Brakes GD Sport"
                },
                {
                    "type": "Application Summary",
                    "description": "2016 ACURA ILX 2.4"
                },
                {
                    "type": "Product Description - Short",
                    "description": "GD Pattern Rotors"
                },
                {
                    "type": "AAIA Part Type Description",
                    "description": "Disc Brake Rotor"
                },
                {
                    "type": "Product Description - Long",
                    "description": "EBC GD ROTOR KIT"
                }
            ],
            "relationships": {
                "vehicle_fitments": {
                    "links": {
                        "self": "/v1/items/fitment/35776"
                    }
                }
            }
        }
    ]
} ```
5w9g7ksd

5w9g7ksd1#

使用您提供的json文件,可以通过以下方法实现:
第一个

相关问题