2

I am currently trying to extract product data from a JSON feed that contains nested data.

The nested structure is looking as follows: http://live.icecat.biz/api/?shopname=openIcecat-live&lang=en&content=featuregroups&icecat_id=1334921

I basically want to extract basic datasheet information for products in the database. Each product has different feature categories at the "top-level" and varying features below that in a nested structure.

My code looks like this so far:

import requests
url2 = 'http://live.icecat.biz/api/?shopname=openIcecat-live&lang=de&content=featuregroups&icecat_id=1334921'

content = requests.get(url).content

j = json.loads(content)    

for each in j['data']['FeaturesGroups']:
    print each ['FeatureGroup']['Name']['Value']

It works fine and prints the headlines of each feature category. But I am unable to parse the individual features. How can I do this ?

My attempt was to use a second loop to iterate over j['data']['FeaturesGroups']['Features'] (see below) but no success :/

for each in j['data']['FeaturesGroups']:
    for each in ['Features']:
        print ['Feature']['ID']

Thanks a lot!

2
  • 1
    for each in ['Features'] -> for each2 in each['Features'] / print ['Feature']['ID'] -> print(each2['ID']). Commented Apr 6, 2018 at 17:15
  • I basically want to extract every single feature per product from the JSON data. And I can't manage to get the data below the "FeatureGroup". But I need the data at: data > FeaturesGroups > 0 > FeatureGroup > Features > Feature > Name > Value. Commented Apr 6, 2018 at 17:18

2 Answers 2

3
import requests
import json
url2 = 'http://live.icecat.biz/api/?shopname=openIcecat-live&lang=de&content=featuregroups&icecat_id=1334921'

content = requests.get(url2).content

j = json.loads(content)

for each in j['data']['FeaturesGroups']:
    print each['FeatureGroup']['Name']['Value']
    for i in each["Features"]:
        print i["ID"]
Sign up to request clarification or add additional context in comments.

Comments

1
import requests
import json
url = 'http://live.icecat.biz/api/?shopname=openIcecat-live&lang=de&content=featuregroups&icecat_id=1334921'

content = requests.get(url).content

j = json.loads(content)    

def find_all(item, level):
    if isinstance(item, dict):
        for k in item:
            print k
            find_all(item[k],level+1)
    else:
        print ' '*level ,item

for each in j['data']['FeaturesGroups']:
    find_all(each['FeatureGroup'], 0)


ID
  3
Name
Language
   DE
ID
   437975
Value
   Speicher
ID
  28
Name
Language
   DE
ID
   437998
Value
   Betriebsbedingungen
ID
  146
Name
Language
   DE
ID
   624349
Value
   Weitere Spezifikationen

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.