Skip to content

Instantly share code, notes, and snippets.

@JamesIgoe
Last active April 9, 2023 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesIgoe/747f8a46393ce9622f970014879b2ec9 to your computer and use it in GitHub Desktop.
Save JamesIgoe/747f8a46393ce9622f970014879b2ec9 to your computer and use it in GitHub Desktop.
Example code to generate JSON from 2 prior lists. Pulled from code that takes 2 DataFrames, one that list members to a add, and one that includes members to remove, then generates nested JSON.
import pandas as pd
import json
memberChange = []
for email in df_add.values:
try:
if email:
memberChange.append({'Email': email[0], 'MemberName': '', 'MemberType': 'Person', 'Action': 'Add'})
except:
pass
for email in df_remove.values:
try:
if email:
memberChange.append({'Email': email[0], 'MemberName': '', 'MemberType': 'Person', 'Action': 'Remove'})
except:
pass
data = {}
data['GroupName'] = group_name
data['ManagerName'] = manager_name
data['Members'] = memberChange
json_data = json.dumps(data)
print(json_data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment