Skip to content

Instantly share code, notes, and snippets.

@meehatpa
Created February 1, 2021 10:54
Show Gist options
  • Save meehatpa/e21134490439f1ea438af32f6b818c52 to your computer and use it in GitHub Desktop.
Save meehatpa/e21134490439f1ea438af32f6b818c52 to your computer and use it in GitHub Desktop.
Combine chrome trace json
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