Skip to content

Instantly share code, notes, and snippets.

@marcus-crane
Created May 22, 2023 23:13
Show Gist options
  • Save marcus-crane/5cb35112f33111fc1887e427e3488405 to your computer and use it in GitHub Desktop.
Save marcus-crane/5cb35112f33111fc1887e427e3488405 to your computer and use it in GitHub Desktop.
A handy script used to convert Logstash testcases from a nested object to flat keys
import glob
import json
import flatdict
tests = glob.glob('logstash/testcases/*.json')
for test in tests:
print(test)
with open(test, 'r') as file:
data = json.loads(file.read())
for case in data['testcases']:
for idx, expect in enumerate(case['expected']):
d = flatdict.FlatDict(expect, delimiter='.')
case['expected'][idx] = dict(d)
with open(test, 'w') as file:
json.dump(data, file, indent=2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment