I would like to print just the date and value?
import json # read file with open('resting_heart_rate-2014-02-28.json') as json_file: data = json.load(json_file) for p in data['dateTime']: print('json_file')fault when running the script:
Error:PS C:\Users\Downloads\heart> C:/Users/erorobi/AppData/Local/Continuum/anaconda3/Scripts/activate
PS C:\Users\Downloads\heart> conda activate base
conda : The term 'conda' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that
the path is correct and try again.
At line:1 char:1
+ conda activate base
+ ~~~~~
+ CategoryInfo : ObjectNotFound: (conda:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
PS C:\Users\Downloads\heart> & C:/Users/AppData/Local/Continuum/anaconda3/python.exe "c:/Users/Downloads/heart/read json.py"
Traceback (most recent call last):
File "c:/Users/Downloads/heart/read json.py", line 6, in <module>
for p in data['dateTime']:
TypeError: list indices must be integers or slices, not str
PS C:\Users\Downloads\heart>
json file format:Output:[{
"dateTime" : "02/27/15 00:00:00",
"value" : {
"date" : "02/27/15",
"value" : 75.0,
"error" : 9.0
}
}]