Skip to content

Commit fc827c9

Browse files
authored
Merge pull request #72 from GeorgeK1ng/develop
Added support for JSON with comments
2 parents fb2b5ac + 5daf766 commit fc827c9

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

.github/validate_json.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import json
1+
import jstyleson
22
import glob
33
import os
44
import sys
5-
import urllib.request
65

76
from ignore_json import ignore
87

@@ -11,14 +10,16 @@
1110
for filename in glob.glob(os.path.join('.', '*.json')):
1211
if filename not in ignore:
1312
print(f"Opening: {filename}")
14-
filecontent = open(filename, "r").read()
13+
14+
with open(filename, "r") as file:
15+
filecontent = file.read()
1516

1617
try:
17-
json.loads(filecontent)
18+
jstyleson.loads(filecontent)
1819
print(f"✅ JSON valid")
1920
except Exception as err:
2021
error = True
21-
print(f"❌ JSON invalid:")
22+
print(f"❌ JSON invalid in {filename}:")
2223
print(str(err))
2324

2425
if error:

.github/validate_mod_json.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import json
1+
import jstyleson
22
import glob
33
import os
44
import sys
@@ -12,21 +12,29 @@
1212
if filename not in ignore:
1313
print(f"Opening: {filename}")
1414
filecontent = open(filename, "r").read()
15-
modlist = json.loads(filecontent)
15+
16+
try:
17+
modlist = jstyleson.loads(filecontent)
18+
except Exception as err:
19+
error = True
20+
print(f"❌ Error reading JSON file {filename}: {err}")
21+
continue
22+
1623
for mod, data in modlist.items():
1724
url = data["mod"].replace(" ", "%20")
1825
print(f"{mod}: {url}")
1926
try:
2027
response = urllib.request.urlopen(url)
2128
print(f"✅ Download successful")
22-
except:
29+
except Exception as err:
2330
error = True
24-
print("❌ Download failed")
31+
print(f"❌ Download failed: {err}")
2532
continue
33+
2634
filecontent = response.read()
27-
35+
2836
try:
29-
json.loads(filecontent)
37+
jstyleson.loads(filecontent)
3038
print(f"✅ JSON valid")
3139
except Exception as err:
3240
error = True

0 commit comments

Comments
 (0)