-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_json.py
33 lines (23 loc) · 978 Bytes
/
extract_json.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import json
myJsonString = open('data/practise.json')
jsonObjects = json.load(myJsonString)
myFile = open('test2.json','w')
myFile.writelines('[')
jsonCounterPosition = 0
jsonObjectsSize = len(jsonObjects)
for jsonObject in jsonObjects:
jsonCounterPosition += 1
jsonDict = dict()
jsonDict['created_at'] = jsonObject['created_at'].replace("+0000 ","")
jsonDict['location'] = jsonObject['user']['location']
jsonDict['followers_count'] = jsonObject['user']['followers_count']
jsonDict['friends_count'] = jsonObject['user']['friends_count']
jsonDict['listed_count'] = jsonObject['user']['listed_count']
jsonDict['favourites_count'] = jsonObject['user']['favourites_count']
jsonDict['retweet_count'] = jsonObject['retweet_count']
jsonDict['text'] = jsonObject['text']
myFile.write(json.dumps(jsonDict, indent=4))
if(jsonCounterPosition < jsonObjectsSize):
myFile.writelines(',')
myFile.writelines(']')
myFile.close()