{"record":{"id":"16636b45859e4067","repo":"Budibase/budibase","slug":"project-package-contains-invalid-json-in-basena","errorCode":null,"errorMessage":"Project package contains invalid JSON in '${basename(filePath)}'.","messagePattern":"Project package contains invalid JSON in '(.+?)'\\.","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/sdk/workspace/projects/backups/imports.ts","lineNumber":142,"sourceCode":"}\n\ninterface InsertedDocRef {\n  _id: string\n  _rev: string\n}\n\ninterface ProjectPackageTarEntry {\n  path: string\n  type?: string\n  size?: number\n  resume?: () => void\n}\n\nconst readJsonFile = async <T>(filePath: string): Promise<T> => {\n  try {\n    return JSON.parse(await fsp.readFile(filePath, \"utf8\"))\n  } catch {\n    throw new HTTPError(\n      `Project package contains invalid JSON in '${basename(filePath)}'.`,\n      400\n    )\n  }\n}\n\nconst toTimestamp = (timestamp?: string | number) => {\n  if (timestamp == null) {\n    return undefined\n  }\n  const date = new Date(timestamp)\n  return Number.isNaN(date.getTime()) ? undefined : date.toISOString()\n}\n\nconst getProjectCreatedAt = (project: Project) =>\n  toTimestamp(project.createdAt) ??\n  toTimestamp(project.updatedAt) ??\n  new Date().toISOString()","sourceCodeStart":124,"sourceCodeEnd":160,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/sdk/workspace/projects/backups/imports.ts#L124-L160","documentation":"readJsonFile reads a file from an extracted project package and JSON.parse's it; any parse or read failure is converted into this 400 HTTPError naming the offending file. It protects the import pipeline from corrupted or non-JSON files inside a .tar.gz project package.","triggerScenarios":"Importing a project package where manifest.json, project.json, or the dependency index is truncated, empty, HTML (e.g. an error page saved as .json), contains comments/trailing commas, or was produced by an incompatible/older export format.","commonSituations":"Partial/corrupted downloads of the export archive; hand-editing package JSON and breaking syntax; exporting from a much older Budibase version and importing into a newer one; archiving tools mangling file contents.","solutions":["Re-export the project from a healthy app and retry the import","Validate the named file's JSON locally (jq or JSON.parse) to see the syntax problem","Open/repair the file in the extracted package if hand-crafting the archive","Confirm the package came from a compatible Budibase version"],"exampleFix":"// before\n// manifest.json last line: \"name\": \"App\",  <- trailing comma\n// after\n// manifest.json last line: \"name\": \"App\"    <- valid JSON, import succeeds","handlingStrategy":"validation","validationCode":"const content = await fsp.readFile(filePath, \"utf8\")\ntry {\n  JSON.parse(content)\n} catch (e) {\n  throw new Error(`${basename(filePath)} is not valid JSON: ${(e as Error).message}`)\n}","typeGuard":"function isJsonParsable(s: string): boolean {\n  try { JSON.parse(s); return true } catch { return false }\n}","tryCatchPattern":"try {\n  await importProject(packagePath)\n} catch (e) {\n  if (e instanceof HTTPError && e.status === 400 && e.message.includes(\"invalid JSON\")) {\n    // extract package, validate/repair the named file, repackage\n  } else throw e\n}","preventionTips":["Checksum/verify downloaded export archives before import","Never hand-edit package JSON without re-validating","Match exporter and importer Budibase versions"],"tags":["import","json","validation","backups"],"backgroundTag":"invalid-json","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}