{"record":{"id":"dcc3c271ecf8eb18","repo":"HelloZeroNet/ZeroNet","slug":"invalid-json-file-s","errorCode":null,"errorMessage":"Invalid json file: %s","messagePattern":"Invalid json file: (.+?)","errorType":"validation","errorClass":"VerifyError","httpStatus":null,"severity":"error","filePath":"src/Content/ContentManager.py","lineNumber":943,"sourceCode":"\n        return True  # All good\n\n    # Verify file validity\n    # Return: None = Same as before, False = Invalid, True = Valid\n    def verifyFile(self, inner_path, file, ignore_same=True):\n        if inner_path.endswith(\"content.json\"):  # content.json: Check using sign\n            from Crypt import CryptBitcoin\n            try:\n                if type(file) is dict:\n                    new_content = file\n                else:\n                    try:\n                        if sys.version_info.major == 3 and sys.version_info.minor < 6:\n                            new_content = json.loads(file.read().decode(\"utf8\"))\n                        else:\n                            new_content = json.load(file)\n                    except Exception as err:\n                        raise VerifyError(\"Invalid json file: %s\" % err)\n                if inner_path in self.contents:\n                    old_content = self.contents.get(inner_path, {\"modified\": 0})\n                    # Checks if its newer the ours\n                    if old_content[\"modified\"] == new_content[\"modified\"] and ignore_same:  # Ignore, have the same content.json\n                        return None\n                    elif old_content[\"modified\"] > new_content[\"modified\"]:  # We have newer\n                        raise VerifyError(\n                            \"We have newer (Our: %s, Sent: %s)\" %\n                            (old_content[\"modified\"], new_content[\"modified\"])\n                        )\n                if new_content[\"modified\"] > time.time() + 60 * 60 * 24:  # Content modified in the far future (allow 1 day+)\n                    raise VerifyError(\"Modify timestamp is in the far future!\")\n                if self.isArchived(inner_path, new_content[\"modified\"]):\n                    if inner_path in self.site.bad_files:\n                        del self.site.bad_files[inner_path]\n                    raise VerifyError(\"This file is archived!\")\n                # Check sign\n                sign = new_content.get(\"sign\")","sourceCodeStart":925,"sourceCodeEnd":961,"githubUrl":"https://github.com/HelloZeroNet/ZeroNet/blob/454c0b2e7e000fda7000cba49027541fbf327b96/src/Content/ContentManager.py#L925-L961","documentation":"verifyFile raises VerifyError('Invalid json file: %s') when a downloaded content.json cannot be parsed as UTF-8 JSON. The exception message embeds the underlying json.loads/json.load error. It means the file received from the peer is corrupt, truncated, or not JSON at all, so no further verification can proceed.","triggerScenarios":"verifyFile is called by isModified while verifying an incoming content.json; the file body fails json.loads (Python <3.6 path decodes utf8 first, otherwise json.load reads the file object) and raises, which is re-raised as VerifyError.","commonSituations":"Truncated downloads from peers, a peer serving an HTML error page instead of content.json, wrong encoding (e.g. UTF-16 or BOM issues on old Python), or a locally corrupted data directory after an interrupted write.","solutions":["Re-download the content.json: delete the file locally (site data dir) so it is fetched again from a healthy peer","Check the file on disk (data/<site>/content.json) — if truncated or HTML, the peer/transport is bad; try other peers","Validate it manually with python -m json.tool data/<site>/content.json to see the exact JSON error","Ensure the file is UTF-8 encoded; convert or re-save it if a tool wrote another encoding"],"exampleFix":"// before: serving a content.json edited by a tool that emitted invalid JSON\n{\"modified\": 1500000000, \"files\": {\"index.html\": {\"sha512\": \"abc\"},,} }\n// after: valid JSON\n{\"modified\": 1500000000, \"files\": {\"index.html\": {\"sha512\": \"abc\"}}}","handlingStrategy":"validation","validationCode":"import json\ndef valid_json_file(path):\n    try:\n        with open(path, 'rb') as f:\n            json.loads(f.read().decode('utf8'))\n        return True\n    except (UnicodeDecodeError, ValueError):\n        return False","typeGuard":null,"tryCatchPattern":"from Content.ContentManager import VerifyError\ntry:\n    site.content_manager.isModified(inner_path, file)\nexcept VerifyError as e:\n    if str(e).startswith('Invalid json file'):\n        redownload(inner_path)  # delete file and fetch from other peers\n    else:\n        raise","preventionTips":["Always save content.json as UTF-8 without BOM","Validate JSON with python -m json.tool before publishing","Watch for peers serving HTML error pages instead of files"],"tags":["zeronet","json-parse","content-verification","corrupt-file"],"backgroundTag":"invalid-json","analyzedSha":"454c0b2e7e000fda7000cba49027541fbf327b96","analyzedAt":"2026-09-02T19:46:57.278Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}