How to handle JSON file with Python

  


How to handle JSON file with Python

  • In this blog we will see how we can handle Json file with python code.
  • Below is the link for JSON file which i am using to work with python
  • JSON File
  • Below are the sample to code to retrieve different information from this file using python.
  • Before running all these below code i am assigning json file values in a variable called "temp".

# To count how many feeds we have in this file
len(temp["feeds"])

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 

# To print all the ids we have in each of the feeds

for var in (temp["feeds"]):

    print(var["id"])

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# To print all multiMedia values we have in each of the feeds

for var in (temp["feeds"]):

    print(var["multiMedia"])

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# To print hierarchical values (URL) present in multiMedia values we have in each of the feeds

for var in (temp["feeds"]):

    for id in var["multiMedia"]:

        print(id['url']) 

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 # To print hirearchical values (URL) which start from "http" present in multiMedia values we have in each of the feeds

for var in (temp["feeds"]):

    for id in var["multiMedia"]:

        if (id["url"]).startswith('http') == True:

            print((id["url"]))



  • Please let me know if you want any specific json file to be handled in the python.






Post a Comment