Created
February 1, 2021 10:54
-
-
Save meehatpa/e21134490439f1ea438af32f6b818c52 to your computer and use it in GitHub Desktop.
Combine chrome trace json
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
import json | |
import glob | |
import os | |
import re | |
def clean_json(string): | |
string = re.sub(",[ \t\r\n]+}", "}", string) | |
string = re.sub(",[ \t\r\n]+\]", "]", string) | |
string = re.sub(",$", "", string) | |
string = re.sub(r"^\[", "", string) | |
string = re.sub(r"\n", "", string) | |
return string | |
result = [] | |
for f in glob.glob(".*.json"): | |
if f == 'all.json': | |
continue | |
if os.path.getsize(f) >> 20 < 1: | |
continue | |
print("File:", f) | |
with open(f) as infile: | |
for row in infile: | |
row = clean_json(row) | |
if len(row) == 0: | |
continue | |
try: | |
jsonparse = json.loads(row) | |
result.append(jsonparse) | |
except Exception as e: | |
print(e) | |
print(len(row) , ':\"' + row + '\"') | |
exit(1) | |
#result.append(json.load(infile)) | |
with open("all.json", "w") as outfile: | |
json.dump(result, outfile) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment