Created
May 22, 2023 23:13
-
-
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
This file contains 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
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