改变JSON结构

改变JSON结构,json,Json,所以我用一个webscraper从一个网站上获取关于运动鞋的信息。返回的子数据的结构如下 [ { "web-scraper-order": "1554084909-97", "web-scraper-start-url": "https://www.goat.com/sneakers", "productlink": "$200AIR JORDAN 6 RET

所以我用一个webscraper从一个网站上获取关于运动鞋的信息。返回的子数据的结构如下

[
  {
    "web-scraper-order": "1554084909-97",
    "web-scraper-start-url": "https://www.goat.com/sneakers",
    "productlink": "$200AIR JORDAN 6 RETRO 'INFRARED' 2019",
    "productlink-href": "https://www.goat.com/sneakers/air-jordan-6-retro-black-infrared-384664-060",
    "name": "Air Jordan 6 Retro 'Infrared' 2019",
    "price": "Buy New - $200",
    "description": "The 2019 edition of the Air Jordan 6 Retro ‘Infrared’ is true to the original colorway, which Michael Jordan wore when he captured his first NBA title. Dressed primarily in black nubuck with a reflective 3M layer underneath, the mid-top features Infrared accents on the midsole, heel tab and lace lock. Nike Air branding adorns the heel and sockliner, an OG detail last seen on the 2000 retro.",
    "releasedate": "2019-02-16",
    "colorway": "Black/Infrared 23-Black",
    "brand": "Air Jordan",
    "designer": "Tinker Hatfield",
    "technology": "Air",
    "maincolor": "Black",
    "silhouette": "Air Jordan 6",
    "nickname": "Infrared",
    "category": "lifestyle",
    "image-src": "https://image.goat.com/crop/1250/attachments/product_template_additional_pictures/images/018/675/318/original/464372_01.jpg.jpeg"
  },
  {
    "web-scraper-order": "1554084922-147",
    "web-scraper-start-url": "https://www.goat.com/sneakers",
    "productlink": "$190YEEZY BOOST 350 V2 'CREAM WHITE / TRIPLE WHITE'",
    "productlink-href": "https://www.goat.com/sneakers/yeezy-boost-350-v2-cream-white-cp9366",
    "name": "Yeezy Boost 350 V2 'Cream White / Triple White'",
    "price": "Buy New - $220",
    "description": "First released on April 29, 2017, the Yeezy Boost 350 V2 ‘Cream White’ combines a cream Primeknit upper with tonal cream SPLY 350 branding, and a translucent white midsole housing full-length Boost. Released again in October 2018, this retro helped fulfill Kanye West’s oft-repeated ‘YEEZYs for everyone’ Twitter mantra, as adidas organized the biggest drop in Yeezy history by promising pre-sale to anyone who signed up on the website. Similar to the first release, the ‘Triple White’ 2018 model features a Primeknit upper, a Boost midsole and custom adidas and Yeezy co-branding on the insole.",
    "releasedate": "2017-04-29",
    "colorway": "Cream White/Cream White/Core White",
    "brand": "adidas",
    "designer": "Kanye West",
    "technology": "Boost",
    "maincolor": "White",
    "silhouette": "Yeezy Boost 350",
    "nickname": "Cream White / Triple White",
    "category": "lifestyle",
    "image-src": "https://image.goat.com/crop/1250/attachments/product_template_additional_pictures/images/014/822/695/original/116662_03.jpg.jpeg"
  },
但是,我想更改它,以便顶级节点是运动鞋,下一级节点是特定的运动鞋品牌Jordan、Nike、Adidas,然后是属于该品牌的运动鞋列表。所以我的JSON结构看起来像这样

Sneakers {
Adidas :{
[shoe1,
 shoe2,
 ....

] },
Jordan: {
[shoe1,
 shoe2,
 ....

]
}
}

我不知道我可以用什么工具来做这件事。任何帮助都将不胜感激。目前我所拥有的只是JSON文件,它不是我想要的结构。

一种方法是填充一个dict,其键是品牌名称,其值是运动鞋记录列表。假设数据是您的原始列表,下面是代码:

sneakers_by_brand = {}

for record in data:
    if sneakers_by_brand.get(record.get("brand")):
        sneakers_by_brand[record.get("brand")].append(record)
    else:
        sneakers_by_brand[record.get("brand")] = [record]

print(sneakers_by_brand)

为什么我可能会被拒绝,因为你的问题没有包含任何试图自己解决这个问题的尝试。