Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
json api data parsing
#1
Having issue with this piece of code, its an api that has json text but its not readable.
in _get_mean_subclass
for prod, v in response_API.item():
Attribute error: 'list' object has no attribute 'item'

response_API = requests.get(
    f"https://api.bestbuy.com/v1/products(manufacturer=canon)?format=json&apiKey={cred.api_key}"
).json()


def _get_mean_subclass(response_API):
    r = defaultdict(list)
    for prod, v in response_API.items():
        # looking for keyword subclass or whatever its called
        r[prod].append(v["subclassId"])
    return {k: mean(v) for k, v in r.items()}


print(_get_mean_subclass(response_API["products"]))
Larz60+ write Apr-22-2022, 05:16 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed for you this time. Please use BBCode tags on future posts.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 227 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  Parsing large JSON josvink66 5 670 Jan-10-2024, 05:46 PM
Last Post: snippsat
Video doing data treatment on a file import-parsing a variable EmBeck87 15 2,912 Apr-17-2023, 06:54 PM
Last Post: EmBeck87
  Read nested data from JSON - Getting an error marlonbown 5 1,383 Nov-23-2022, 03:51 PM
Last Post: snippsat
  Reading Data from JSON tpolim008 2 1,097 Sep-27-2022, 06:34 PM
Last Post: Larz60+
  Parsing JSON pyStund 4 3,006 Jul-31-2022, 02:02 PM
Last Post: pyStund
  Convert nested sample json api data into csv in python shantanu97 3 2,854 May-21-2022, 01:30 PM
Last Post: deanhystad
  Struggling with Juggling JSON Data SamWatt 7 1,902 May-09-2022, 02:49 AM
Last Post: snippsat
  Json Parsing sshree43 5 1,807 May-04-2022, 09:21 PM
Last Post: snippsat
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,695 Apr-13-2022, 06:02 AM
Last Post: Paqqno

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020