cancel
Showing results for 
Search instead for 
Did you mean: 

Parsing .txt from API "Export Users By Segment"

ahmaddiaa
Active Member

Hello Everyone!
I manage a daily newsletter. To measure user engagement, we categorize users by how many emails they open per week. 

I'm facing trouble using the export file from "Export Users By Segment" API endpoint. here is my workflow:

  1. export "External_id" and " campaigns_received" fields from the recipient segment.
  2. for each External_id, check how of last week's emails are "opened"
  3. throw that data into my python script to graph the % of users who open emails 5, 4, 3, 2, 1 times a week.

How can i parse the exported user details to look readable, like the sample braze response? this will make it tons easier to understand and therefore work with the data.
Here is what the (dummy) data looks like

Screenshot 2024-03-13 at 10.44.24 PM.png

vs what i want it to look like:
Screenshot 2024-03-13 at 10.45.45 PM.pngThanks a lot!!

1 REPLY 1

Max
Specialist

Hey! You can use a simple JSON formatter or do it directly in your Python script. 

Here one simple example:

import json

# JSON string
json_string = '{"name": "John", "age": 30, "city": "New York"}'

# Convert JSON string to Python dictionary
data = json.loads(json_string)

# Convert Python dictionary back to JSON string with indentation
formatted_json = json.dumps(data, indent=4)

print(formatted_json)