Last active
November 4, 2023 20:55
-
-
Save bluPhy/5343be750ca33ee8c891ce980402067c to your computer and use it in GitHub Desktop.
iam-json-reformat.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# Python script to reformat IAM json data | |
# Author: Rajathithan Rajasekar - 03/03/2020 | |
import json,ast,sys | |
data = [] | |
project = "" | |
def hello(jdata, project): | |
nicedata = ast.literal_eval(json.dumps(jdata, indent=4, sort_keys=True)) | |
for i in range(len(nicedata)): | |
indrow = nicedata[i] | |
usersandservice = indrow['members'] | |
for j in range(len(usersandservice)): | |
print("{},{},{}".format(project, indrow['role'], usersandservice[j])) | |
project = sys.argv[1] | |
data = sys.stdin.read() | |
data = data.replace("u\'", "\"") | |
data = data.replace("\'", "\"") | |
jdata = json.loads(data) | |
hello(jdata, project) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment