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
#1
So im playing around with parsing a json file in python.
Im able to read in the file and print it to the console, but now i want to extract 3 values from each "section" not sure what the proper terminology is.

Here is a example of the data structure..:
  "messages": [
    {
      "sender_name": "Me",
      "timestamp_ms": 1653260883178,
      "content": "There are plenty of leftovers",
      "type": "Generic",
      "is_unsent": false,
      "is_taken_down": false,
      "bumped_message_metadata": {
        "bumped_message": "There are plenty of leftovers",
        "is_bumped": false
      }
    },
    {
      "sender_name": "Me",
      "timestamp_ms": 1653260872966,
      "content": "Watching the new scream movie",
      "type": "Generic",
      "is_unsent": false,
      "is_taken_down": false,
      "bumped_message_metadata": {
        "bumped_message": "Watching the new scream movie",
        "is_bumped": false
      }
    },
I basically need to pull out only the first 3 sets of values and save it into a CSV file.

      "sender_name": "Me",
      "timestamp_ms": 1653260883178,
      "content": "There are plenty of leftovers",
Right now i have this basic simple code, but need to figure out how to get within the "message" section and pull out those 3 values per group

import json

f = open('message_1.json')

data = json.load(f)

for i in data['messages']:
     print(i)

f.close()
Reply


Messages In This Thread
Trying to parse only 3 key values from json file - by cubangt - May-24-2022, 09:04 PM

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