Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

I need help pulling/search data from Json

hello  below is my code
PHP Code

<?php 
import urllib
.request
import json
##inp = input("enter website address : ")
##url= urllib.request.urlopen("http://freegeoip.net/json/{}".format(inp))
url= urllib.request.urlopen("http://data.gov.jm/api/action/datastore/search.json?resource_id=da5f0429-18ba-4d38-bd03-26171b81309c&limit=1")

data = json.loads(url.read().decode())
#print('IP : {}'.format(data['ip']))
print(data)
#print('Division : {}'.format(data['Clarendon']))
#print('Year : {}'.format(data[2007]))
#print('Fatalities : {}'.format(data['']))
#print(data["Division"])
if data[{"Division"}] == "Clarendon":
 
   print(data[{"Division"}])
 
   print(data[{"Fatalities"}])
 
    
i want to be able to search for specific data in this json api
Knowledge is Power - Be Powerful!!!!!


LIFE IS A CHALLENGE SO ACCEPT IT!
You get a list of results from that JSON result with:
PHP Code

<?php 
data
["result"]["records"] 

I assume there can be more than one result; however, to get the first result, you'd call it like such:
PHP Code

<?php 
data
["result"]["records"][0] 
That will be a dictionary containing the following keys:
Code
Division
Fatal accidents
Fatalities
Year

If you want to loop through to find a specific division, you'd use something like this:
PHP Code

<?php 
for division in data["result"]["records"]:
    print(
division["Division"])
    if 
division["Division"] == "whatever":
        
# do stuff 

hi


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by roosiinfidel09May 26, 2021 06:32 AM 1 274 May 26, 2021 06:32 AM
Last Post: h0lyl337
[.NET] by outlawNov 28, 2020 04:25 AM 12 367 Nov 28, 2020 04:25 AM
Last Post: Rmdy
[C#] by HardStoNAug 15, 2020 03:56 AM 6 294 Aug 15, 2020 03:56 AM
Last Post: HardStoN