I want to import in my python program only some fields of a JSON file composed of lines of the following type:
{
"business_id":"Apn5Q_b6Nz61Tq4XzPdf9A",
"name":"Minhas Micro Brewery",
"neighborhood":"",
"address":"1314 44 Avenue NE",
"city":"Calgary",
"state":"AB",
"postal_code":"T2E 6L6",
"latitude":51.0918130155,
"longitude":-114.031674872,
"stars":4.0,
"review_count":24,
"is_open":1,
"attributes":{
"BikeParking":"False",
"BusinessAcceptsCreditCards":"True",
"BusinessParking":"{'garage': False, 'street': True, 'validated': False, 'lot': False, 'valet': False}",
"GoodForKids":"True",
"HasTV":"True",
"NoiseLevel":"average",
"OutdoorSeating":"False",
"RestaurantsAttire":"casual",
"RestaurantsDelivery":"False",
"RestaurantsGoodForGroups":"True",
"RestaurantsPriceRange2":"2",
"RestaurantsReservations":"True",
"RestaurantsTakeOut":"True"
},
"categories":"Tours, Breweries, Pizza, Restaurants, Food, Hotels & Travel",
"hours":{
"Monday":"8:30-17:0",
"Tuesday":"11:0-21:0",
"Wednesday":"11:0-21:0",
"Thursday":"11:0-21:0",
"Friday":"11:0-21:0",
"Saturday":"11:0-21:0"
}
}
For example I would like to import only the fields: business_id, name and categories. I tried in different ways, but the program does not recognize the fields and each line is seen as a single field. For example, I have this problem using the following command:
x = pd.read_json('.../data.json')
I also tried to import it like this:
with open('.../data.json', 'r') as f:
x = json.load(f)
When I try the command
x = x["business_id","name","categories"]
it returns the following error
KeyError: "['business_id' 'name' 'categories'] not in index"
The program does not recognize the fields in any way.