Skip to content

Instantly share code, notes, and snippets.

@rhydlewis
Created December 7, 2023 13:42
Show Gist options
  • Save rhydlewis/b7f62836a9a0d391582a63d2f319b890 to your computer and use it in GitHub Desktop.
Save rhydlewis/b7f62836a9a0d391582a63d2f319b890 to your computer and use it in GitHub Desktop.
Redact Jira JSON export File
import json
# TODO - redact jira instance name
def redact_data(data):
if isinstance(data, dict):
for key, value in data.items():
if key in ['name', 'emailAddress', 'displayName', 'summary', 'description']:
data[key] = 'redacted'
elif key in ['fromString', 'toString']:
# look for very long text e.g. description changes to redact
if data[key] is not None and len(data[key]) > 30:
data[key] = 'redacted'
else:
redact_data(value)
elif isinstance(data, list):
for item in data:
redact_data(item)
input_file = 'jira_export.json'
output_file = 'redacted_jira_export.json'
try:
with open(input_file, 'r', encoding='utf-8') as file:
jira_data = json.load(file)
redact_data(jira_data)
with open(output_file, 'w', encoding='utf-8') as file:
json.dump(jira_data, file, indent=2)
print("Jira export redacted to: ", output_file)
except Exception as e:
print(f"An error occurred: {e}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment