I have a set of JSON files that contains some information.The below data is value for key 'BrowserInfo'.I want to extract the following information
Title , Links, Browser,Platform,CPUs from what is given below, add the above fields as keys in the JSON file and extract their values and assign to those keys.
Title: Worlds best websit | mywebsite.com
Links: 225
Browser: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 Ubuntu Chromium/41.0.2272.76 Chrome/41.0.2272.76 Safari/537.36
Platform: Linux x86_64
CPUs: 8
I have writtten a python program to descent into the directory and extract 'BrowserInfo' value from the JSON files.
# Set the directory you want to start from
rootDir = '/home/space'
for dirName, subdirList, fileList in os.walk(rootDir):
print('Found directory: %s' % dirName)
for fname in fileList:
fname='space/'+fname
with open(fname, 'r+') as f:
json_data = json.load(f)
BrowserInfo = json_data['BrowserInfo']
print(BrowserInfo)
How do I extract the values and add new key-value pairs to JSON files using Python.
BrowserInfoand add them as new key value pairs to the JSON files.json_data[BrowserInfo.key]=BrowserInfo.value?valuefor thekeyBrowserInfo. They are not in JSON format. They need to be parsed I think.