How do you Print Json Object from Json Feed with Python? -


i new python , json , have question regarding getting values json file.

let's have json feed fruits such 1 below:

{    "banana": {     vitamin: "a", },  "apple": {     vitamin: "b", }, "orange": {     vitamin: "c",     }, } 

let's want print object (in case fruits) has vitamin element "c"

i loading json file using:

    import utils      fruits= utils.load_json('feed.json') 

and storing vitamins element in variable so:

      fruit in fruits:            list_of_vitamins= fruits[fruit]['vitamin'] 

i using if statement see if "c" available in list of vitamins , is:

     if ("c" in list_of_vitamins):           print "yes"  

this working fine, trying find away see if "c" exists , if does, print object holds "c", in case, "orange"

so in end want code search json file vitamin c , print fruit orange.

import json  fruits_json= json.load(open('feed.json')) print fruits_json  fruit in fruits_json:   if fruits_json[fruit]["vitamin"] == "c":     print fruit 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -