Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print a JSON file
#1
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 } }]
Reply


Messages In This Thread
Print a JSON file - by mrobie - May-31-2019, 07:00 PM
RE: Print a JSON file - by Yoriz - May-31-2019, 08:26 PM
RE: Print a JSON file - by mrobie - May-31-2019, 08:58 PM
RE: Print a JSON file - by Yoriz - May-31-2019, 09:17 PM
RE: Print a JSON file - by mrobie - May-31-2019, 09:33 PM
RE: Print a JSON file - by Yoriz - May-31-2019, 09:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 271 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  parse json field from csv file lebossejames 4 793 Nov-14-2023, 11:34 PM
Last Post: snippsat
  Python Script to convert Json to CSV file chvsnarayana 8 2,595 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,195 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Converting a json file to a dataframe with rows and columns eyavuz21 13 4,675 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  validate large json file with millions of records in batches herobpv 3 1,310 Dec-10-2022, 10:36 PM
Last Post: bowlofred
  Saving the print result in a text file Calli 8 1,890 Sep-25-2022, 06:38 PM
Last Post: snippsat
  Writing to json file ebolisa 1 1,032 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Trying to parse only 3 key values from json file cubangt 8 3,547 Jul-16-2022, 02:05 PM
Last Post: deanhystad
  failing to print not matched lines from second file tester_V 14 6,192 Apr-05-2022, 11:56 AM
Last Post: codinglearner

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020