Budibase/budibase · error · HTTPError

Project package contains invalid JSON in '${basename(filePat

Error message

Project package contains invalid JSON in '${basename(filePath)}'.

What it means

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.

Source

Thrown at packages/server/src/sdk/workspace/projects/backups/imports.ts:142

}

interface InsertedDocRef {
  _id: string
  _rev: string
}

interface ProjectPackageTarEntry {
  path: string
  type?: string
  size?: number
  resume?: () => void
}

const readJsonFile = async <T>(filePath: string): Promise<T> => {
  try {
    return JSON.parse(await fsp.readFile(filePath, "utf8"))
  } catch {
    throw new HTTPError(
      `Project package contains invalid JSON in '${basename(filePath)}'.`,
      400
    )
  }
}

const toTimestamp = (timestamp?: string | number) => {
  if (timestamp == null) {
    return undefined
  }
  const date = new Date(timestamp)
  return Number.isNaN(date.getTime()) ? undefined : date.toISOString()
}

const getProjectCreatedAt = (project: Project) =>
  toTimestamp(project.createdAt) ??
  toTimestamp(project.updatedAt) ??
  new Date().toISOString()

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Re-export the project from a healthy app and retry the import
  2. Validate the named file's JSON locally (jq or JSON.parse) to see the syntax problem
  3. Open/repair the file in the extracted package if hand-crafting the archive
  4. Confirm the package came from a compatible Budibase version

Example fix

// before
// manifest.json last line: "name": "App",  <- trailing comma
// after
// manifest.json last line: "name": "App"    <- valid JSON, import succeeds
Defensive patterns

Strategy: validation

Validate before calling

const content = await fsp.readFile(filePath, "utf8")
try {
  JSON.parse(content)
} catch (e) {
  throw new Error(`${basename(filePath)} is not valid JSON: ${(e as Error).message}`)
}

Type guard

function isJsonParsable(s: string): boolean {
  try { JSON.parse(s); return true } catch { return false }
}

Try / catch

try {
  await importProject(packagePath)
} catch (e) {
  if (e instanceof HTTPError && e.status === 400 && e.message.includes("invalid JSON")) {
    // extract package, validate/repair the named file, repackage
  } else throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/16636b45859e4067. Report an issue: GitHub.