How to Split Large Automation File into Small Files
Platform Notice: Cloud Only - This article only applies to Atlassian products on the cloud platform.
Summary
Disclaimer
Atlassian does not support the code below, which is provided "AS IS." This article provides a piece of code that illustrates one way to achieve the desired goal.
Feedback provided at the bottom of the page is appreciated, but won't be handled as support.
You need to import a JSON file containing several automation rules and you face the following error:
ERROR
The provided rule import exceeds the maximum file size limit of 5MB. Please reduce the number of rules by splitting your import into smaller files and try again.
Solution
This script requires Python 3 to be installed
The code below assumes you have a json file called "automation-rules.json" with your original rules exported
The code will create a new folder called "output_batches", where the splited files will be placed
The code is set to split the files in batches of 200 rules. This can be changed
Split_rules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import json
import os
def split_json_file(file_path, output_dir, batch_size):
# Ensure output directory exists
os.makedirs(output_dir, exist_ok=True)
# Load the main JSON file
with open(file_path, 'r', encoding='utf-8') as f:
data = json.load(f)
# Check if it's the expected structure
if 'rules' not in data:
print("Invalid JSON format: 'rules' key not found.")
return
# Get the list of rules
rules = data['rules']
total_rules = len(rules)
# Split rules into batches
for i in range(0, total_rules, batch_size):
# Slice the list of rules for the current batch
batch_rules = rules[i:i + batch_size]
batch_data = {"rules": batch_rules}
# Define the output file path
batch_file_name = f"batch_{i // batch_size + 1}.json"
batch_file_path = os.path.join(output_dir, batch_file_name)
# Write the batch to a new JSON file
with open(batch_file_path, 'w', encoding='utf-8') as f:
json.dump(batch_data, f, indent=4)
print(f"Created batch file: {batch_file_path} with {len(batch_rules)} rules")
# Usage example
file_path = 'automation-rules.json' # Path to the large JSON file
output_dir = 'output_batches' # Directory to save the smaller files
batch_size = 200 # Number of rules per batch
split_json_file(file_path, output_dir, batch_size)
Was this helpful?