How to interpret this JSON file?

2024/7/6 21:51:07

I'm trying to interpret this JSON file but I couldn't figure it out.

{"results": [{"fsq_id": "4dc586fbcc3ff3b3045e2ef3","categories": [{"id": 17056,"name": "Flower Store","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/shops/flowershop_","suffix": ".png"}}],"chains": [],"distance": 121,"geocodes": {"main": {"latitude": 60.24277,"longitude": 24.92642}},"location": {"address": "Pakilantie 69","country": "FI","locality": "Helsinki","postcode": "00660","region": "Uusimaa"},"name": "Pakilan Kukkatalo","related_places": {},"timezone": "Europe/Helsinki"},{"fsq_id": "4d972d612bd6f04de0524850","categories": [{"id": 18064,"name": "Soccer Field","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/arts_entertainment/stadium_soccer_","suffix": ".png"}}],"chains": [],"distance": 149,"geocodes": {"main": {"latitude": 60.24221613213154,"longitude": 24.929252754506127}},"location": {"address": "Pakila","country": "FI","cross_street": "","locality": "Helsinki","postcode": "","region": "Uusimaa"},"name": "HPS-halli","related_places": {},"timezone": "Europe/Helsinki"},{"fsq_id": "4f88508ae4b00a6260d51c09","categories": [{"id": 13016,"name": "Lounge","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/nightlife/default_","suffix": ".png"}}],"chains": [],"distance": 177,"geocodes": {"main": {"latitude": 60.24322,"longitude": 24.925877}},"location": {"country": "FI","cross_street": "","postcode": ""},"name": "Vuokrasauna.fi","related_places": {},"timezone": "Europe/Helsinki"},{"fsq_id": "4c097ac53c70b713fdd3275b","categories": [{"id": 17069,"name": "Grocery Store / Supermarket","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/shops/food_grocery_","suffix": ".png"}}],"chains": [],"distance": 280,"geocodes": {"main": {"latitude": 60.239423847583105,"longitude": 24.929011346258985}},"location": {"address": "Pakilantie 61","country": "FI","locality": "Helsinki","postcode": "00660","region": "Uusimaa"},"name": "S-market Pakila","related_places": {"children": []},"timezone": "Europe/Helsinki"},{"fsq_id": "5177bebce4b036dbba157074","categories": [{"id": 17082,"name": "Furniture and Home Store","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/shops/furniture_","suffix": ".png"}}],"chains": [],"distance": 282,"geocodes": {"main": {"latitude": 60.24412692651818,"longitude": 24.92534364400254}},"location": {"address": "Elontie 71","country": "FI","cross_street": "","locality": "Helsinki","postcode": "00660","region": "Uusimaa"},"name": "Parkettilattiat Oy","related_places": {},"timezone": "Europe/Helsinki"},{"fsq_id": "4e95b46e9adfced1a955a6e1","categories": [{"id": 17035,"name": "Drugstore","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/shops/pharmacy_","suffix": ".png"}}],"chains": [],"distance": 388,"geocodes": {"main": {"latitude": 60.23825881820312,"longitude": 24.928175247924628}},"location": {"address": "Pakilantie 56","country": "FI","cross_street": "","locality": "Helsinki","postcode": "00660","region": "Uusimaa"},"name": "Pakilan Apteekki","related_places": {},"timezone": "Europe/Helsinki"},{"fsq_id": "5184e1f3498ef45e57b9a417","categories": [{"id": 13034,"name": "Caf\u00e9","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/food/cafe_","suffix": ".png"}},{"id": 13065,"name": "Restaurant","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/food/default_","suffix": ".png"}}],"chains": [],"distance": 438,"geocodes": {"main": {"latitude": 60.237879766432634,"longitude": 24.928877151037955}},"location": {"address": "Pakilantie 55","country": "FI","cross_street": "Osuuskunnantie","locality": "Helsinki","postcode": "00660","region": "Uusimaa"},"name": "Kahvila Helmi","related_places": {},"timezone": "Europe/Helsinki"},{"fsq_id": "58ab1e4826a4075f5fa3a891","categories": [{"id": 13012,"name": "Hookah Bar","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/nightlife/hookahbar_","suffix": ".png"}}],"chains": [],"distance": 366,"geocodes": {"main": {"latitude": 60.239296,"longitude": 24.922197}},"location": {"country": "FI","cross_street": "","postcode": ""},"name": "Noora's","related_places": {},"timezone": "Europe/Helsinki"},{"fsq_id": "58296da35cc1d73f7580d214","categories": [{"id": 13334,"name": "Sandwich Restaurant","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/food/deli_","suffix": ".png"}}],"chains": [],"distance": 369,"geocodes": {"main": {"latitude": 60.238425,"longitude": 24.928056}},"location": {"address": "Pakilantie 56","country": "FI","cross_street": "","locality": "Helsinki","postcode": "00660","region": "Uusimaa"},"name": "House of Sandwiches","related_places": {},"timezone": "Europe/Helsinki"},{"fsq_id": "4c52d3d9989eb7137441b226","categories": [{"id": 17069,"name": "Grocery Store / Supermarket","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/shops/food_grocery_","suffix": ".png"}}],"chains": [{"id": "e5a2fd48-9989-4012-a8e4-45404edc24e6","name": "R-Kioski"}],"distance": 385,"geocodes": {"main": {"latitude": 60.23828070026192,"longitude": 24.928105045660168}},"location": {"address": "Pakilantie 56","country": "FI","locality": "Helsinki","postcode": "00660","region": "Uusimaa"},"name": "R-Kioski","related_places": {},"timezone": "Europe/Helsinki"},{"fsq_id": "4cce9331ba0a548127874959","categories": [{"id": 13064,"name": "Pizzeria","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/food/pizza_","suffix": ".png"}},{"id": 13145,"name": "Fast Food Restaurant","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/food/fastfood_","suffix": ".png"}}],"chains": [],"distance": 465,"geocodes": {"main": {"latitude": 60.24571426909511,"longitude": 24.924457646189502}},"location": {"address": "Pakilantie 82","country": "FI","cross_street": "Ripusuontie","locality": "Helsinki","postcode": "00660","region": "Uusimaa"},"name": "Pakilan Pizza-Kebab","related_places": {},"timezone": "Europe/Helsinki"}],"context": {"geo_bounds": {"circle": {"center": {"latitude": 60.241687,"longitude": 24.9267659},"radius": 500}}}
}

I want to get 'name', "latitude", "longitude", and 'categories'.

I tried this code but it didn't work:

def getNearbyVenues(names, latitudes, longitudes, radius=500):headers = {"Accept": "application/json","Authorization": "fsq363333333###JtJOrcBK3WguBrzyryQuTrO3hhhsFMzZ3CJo="}URL = "https://api.foursquare.com/v3/places/search?ll={},{}&radius={}&limit={}"venues_list = []for name, lat, lng in zip(names, latitudes, longitudes):print(name)url = URL.format(lat, lng, radius, LIMIT)results = requests.request("GET", url, headers=headers).json()['results']['main'][0]['location']venues_list.append([(name,lat,lng,v['venue']['name'],v['venue']['location']['lat'],v['venue']['location']['lng'],v['venue']['categories'][0]['name']) for v in results])nearby_venues = pd.DataFrame([item for venue_list in venues_list for item in venue_list])nearby_venues.columns = ['Neighborhood','Neighborhood Latitude','Neighborhood Longitude','Venue','Venue Latitude','Venue Longitude','Venue Category']return(nearby_venues)

What should I edit so it works?

Answer

I cut your data into two entries so, you don't get to see a lot of data.you can scroll to bottom to see what code I wrote.

data = {"results": [{"fsq_id": "4dc586fbcc3ff3b3045e2ef3","categories": [{"id": 17056,"name": "Flower Store","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/shops/flowershop_","suffix": ".png",},}],"chains": [],"distance": 121,"geocodes": {"main": {"latitude": 60.24277, "longitude": 24.92642}},"location": {"address": "Pakilantie 69","country": "FI","locality": "Helsinki","postcode": "00660","region": "Uusimaa",},"name": "Pakilan Kukkatalo","related_places": {},"timezone": "Europe/Helsinki",},{"fsq_id": "4d972d612bd6f04de0524850","categories": [{"id": 18064,"name": "Soccer Field","icon": {"prefix": "https://ss3.4sqi.net/img/categories_v2/arts_entertainment/stadium_soccer_","suffix": ".png",},}],"chains": [],"distance": 149,"geocodes": {"main": {"latitude": 60.24221613213154, "longitude": 24.929252754506127}},"location": {"address": "Pakila","country": "FI","cross_street": "","locality": "Helsinki","postcode": "","region": "Uusimaa",},"name": "HPS-halli","related_places": {},"timezone": "Europe/Helsinki",},S],"context": {"geo_bounds": {"circle": {"center": {"latitude": 60.241687, "longitude": 24.9267659},"radius": 500,}}},
}df_mapping = []
from unicodedata import category
import pandas as pd
result = data['results']
for entry in result:name = entry["name"]category = entry["categories"][0]['name']geocode_dct = entry['geocodes']['main']lat = geocode_dct['latitude']lon = geocode_dct['longitude']df_mapping.append({"name": name,"lat": lat,"lon": lon,"category": category})
df = pd.DataFrame(df_mapping)
print(df)

output

                   name        lat        lon                     category
0     Pakilan Kukkatalo  60.242770  24.926420                 Flower Store
1             HPS-halli  60.242216  24.929253                 Soccer Field
2        Vuokrasauna.fi  60.243220  24.925877                       Lounge
3       S-market Pakila  60.239424  24.929011  Grocery Store / Supermarket
4    Parkettilattiat Oy  60.244127  24.925344     Furniture and Home Store
5      Pakilan Apteekki  60.238259  24.928175                    Drugstore
6         Kahvila Helmi  60.237880  24.928877                         Café
7               Noora's  60.239296  24.922197                   Hookah Bar
8   House of Sandwiches  60.238425  24.928056          Sandwich Restaurant
9              R-Kioski  60.238281  24.928105  Grocery Store / Supermarket
10  Pakilan Pizza-Kebab  60.245714  24.924458                     Pizzeria
https://en.xdnf.cn/q/120061.html

Related Q&A

How to extract a field from this payload with a regex? [duplicate]

This question already has answers here:Parse JSON with Python(2 answers)Closed 6 years ago.I have this payload that I wish to extract a field from:{"encrypted_sender_transaction_id":"514…

Python reading xml

I am newbie on Python programming. I have requirement where I need to read the xml structure and build the new soap request xml by adding namespace like here is the example what I have Below XML which …

How can sum two nested list in this situation

Given list a, b a=[[[1.1,-2.1],[-0.6,4.2]],[[3.9,1.3],[-1.3,1.2]]]b=[[-1.1,4.3],[-1.4,2.4]]If I just want to sum the list [[1.1,-2.1],[-0.6,4.2]] in the list a (not the whole list a) with the list [-1.…

Create check digit function

Im trying to create check digits and append them after the original UPCs. Heres the sample data Because there are leading 0s, I have to read the data as strings first: import pandas as pd …

Getting count of permutations in a faster way

Using this code to get count of permutations is slow on big numbers as the partition part takes long time to calculate all the partitions for a number like 100 and because of all the partitions in the …

How to find number of vowels in each word of string? [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

Python error: AttributeError: str object has no attribute read

My full code:import requests as req import json Bin = int(300000) BinMax = int(600000) File = open("C:/Users/admin/Desktop/PS Now Generaetors/Bins.txt", a)while bin != BinMax:json1 = req.get(…

list elements sum of one list first element to last element of second list

How to sum first element of one list to last element of second list if both list contains same amount of elements in python. Source code (should be kind of like this): def update(l1,l2,l3):for i in ran…

Append float data at the end of each line in a text file

I have a .txt file and Im trying to add float number at the end of each line with incremented value than the last line. This is what I have in the .txt file:>520.980000 172.900000 357.440000 >320…

Change and Sort list in list in specific order in python

Hello guys I have this type of data in list in list array = [ ["PRODUCT NAME PACK","BAIGAM KOT","FIAZ BAGH","OLD ANARKALI","SULTAN PURA","TEZAB AA…