Python Forum
Trying to parse only 3 key values from json file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trying to parse only 3 key values from json file
#4
So here is what i have and seems to work, now im trying to save this to a CSV so i can test importing it into my excel report

import json
from datetime import datetime

f = open('messages.json')

data = json.load(f)

for message in data["messages"]:
    timestamp = datetime.fromtimestamp(message["timestamp_ms"] / 1000)
    
    if 'content' not in message:
        print(
            f"""{timestamp} from {message["sender_name"]}\n"""
        )
    else:
        print(
            f"""{timestamp} from {message["sender_name"]}\n{message["content"]}\n"""
        )

f.close()
Reply


Messages In This Thread
RE: Trying to parse only 3 key values from json file - by cubangt - May-25-2022, 02:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  encrypt data in json file help jacksfrustration 1 467 Mar-28-2024, 05:16 PM
Last Post: deanhystad
  parse json field from csv file lebossejames 4 902 Nov-14-2023, 11:34 PM
Last Post: snippsat
  parse/read from file seperated by dots giovanne 5 1,258 Jun-26-2023, 12:26 PM
Last Post: DeaD_EyE
  Python Script to convert Json to CSV file chvsnarayana 8 2,782 Apr-26-2023, 10:31 PM
Last Post: DeaD_EyE
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,419 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  [split] Parse Nested JSON String in Python mmm07 4 1,705 Mar-28-2023, 06:07 PM
Last Post: snippsat
  Converting a json file to a dataframe with rows and columns eyavuz21 13 5,271 Jan-29-2023, 03:59 PM
Last Post: eyavuz21
  validate large json file with millions of records in batches herobpv 3 1,404 Dec-10-2022, 10:36 PM
Last Post: bowlofred
  Writing to json file ebolisa 1 1,102 Jul-17-2022, 04:51 PM
Last Post: deanhystad
  Modify values in XML file by data from text file (without parsing) Paqqno 2 1,861 Apr-13-2022, 06:02 AM
Last Post: Paqqno

Forum Jump:

User Panel Messages

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