I am making a mod manager which opens the mods manifest.json file for name, description, version and dependencies although when its reading the file… i think ill just show you:
MANIFEST FILE:
{
"name": "HookGenPatcher",
"version_number": "0.0.5",
"website_url": "https://github.com/harbingerofme/Bepinex.Monomod.HookGenPatcher",
"description": "Generates MonoMod.RuntimeDetour.HookGen's MMHOOK file during the BepInEx preloader phase.",
"dependencies": []
}
CODE:
from json import JSONDecoder
json = JSONDecoder()
PLUGIN_PATH: str = "./mods"
plugins: dict[str: dict[str: str]] = {}
for mod in os.listdir(path = PLUGIN_PATH):
mod_path: str = f"{PLUGIN_PATH}/{mod}"
if is_zipfile(filename = mod_path):
folder_path: str = ".".join(mod_path.split(sep = ".")[:-1])
os.mkdir(path = folder_path)
mod_zip = ZipFile(file = mod_path)
mod_zip.extractall(path = folder_path)
mod_zip.close()
os.remove(path = mod_path)
with open(file = f"{mod_path}/manifest.json", mode = "r") as f:
x: list[str] = f.read()
y: list = []
for line in x.splitlines():
y.append(line.strip())
y = "".join(y)
print(y)
mod_json: dict = json.decode(s = y)
plugins[mod] = mod_json
print(plugins)
OUTPUT:
{"name": "HookGenPatcher","version_number": "0.0.5","website_url": "https://github.com/harbingerofme/Bepinex.Monomod.HookGenPatcher","description": "Generates MonoMod.RuntimeDetour.HookGen's MMHOOK file during the BepInEx preloader phase.","dependencies": []}
Traceback (most recent call last):
File "d:OneDriveCodeBetterLCModsmain.pyw", line 58, in <module>
mod_json: dict = json.decode(s = y)
^^^^^^^^^^^^^^^^^^
File "E:PythonLibjsondecoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:PythonLibjsondecoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
This is only to this manifest file and ive tried deleting it and typing it back out (not copy pasting it)
Im guessing its the "" at the start of the file but I have no idea why that is there.
2
Answers
Best way / Only way is to add this
And can you guys not spam downvote this question because you didn't read anything I was saying.
THE WHOLE NEW FILE:
Maybe this demonstration of what a utf-8-sig file looks like will help.
Output:
The code only wrote 5 characters to the file but 8 bytes were generated due to the 3-character BOM used for this encoding