May-24-2022, 09:04 PM
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.
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()