Forum Discussion

ahmaddiaa's avatar
ahmaddiaa
Active Member
6 months ago

Parsing .txt from API "Export Users By Segment"

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

vs what i want it to look like:
Thanks a lot!!

1 Reply

  • Max's avatar
    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)