{"record":{"id":"52a13fb9dc35bc7a","repo":"GoogleChrome/lighthouse","slug":"json-file-was-not-generated-by-lighthouse","errorCode":null,"errorMessage":"JSON file was not generated by Lighthouse","messagePattern":"JSON file was not generated by Lighthouse","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"viewer/app/src/lighthouse-report-viewer.js","lineNumber":161,"sourceCode":"        .then(resp => resp.json())\n        .then(json => {\n          this._reportIsFromJSON = true;\n          this._replaceReportHtml(json);\n        })\n        .catch(err => logger.error(err.message));\n    }\n\n    return loadPromise.finally(() => this._toggleLoadingBlur(false));\n  }\n\n  /**\n   * Basic Lighthouse report JSON validation.\n   * @param {LH.Result} reportJson\n   * @private\n   */\n  _validateReportJson(reportJson) {\n    if (!reportJson.lighthouseVersion) {\n      throw new Error('JSON file was not generated by Lighthouse');\n    }\n\n    // Leave off patch version in the comparison.\n    const semverRe = new RegExp(/^(\\d+)?\\.(\\d+)?\\.(\\d+)$/);\n    const reportVersion = reportJson.lighthouseVersion.replace(semverRe, '$1.$2');\n    const lhVersion = window.LH_CURRENT_VERSION.replace(semverRe, '$1.$2');\n\n    if (reportVersion < lhVersion) {\n      // TODO: figure out how to handler older reports. All permalinks to older\n      // reports will start to throw this warning when the viewer rev's its\n      // minor LH version.\n      // See https://github.com/GoogleChrome/lighthouse/issues/1108\n      logger.warn('Results may not display properly.\\n' +\n                  'Report was created with an earlier version of ' +\n                  `Lighthouse (${reportJson.lighthouseVersion}). The latest ` +\n                  `version is ${window.LH_CURRENT_VERSION}.`);\n    }\n  }","sourceCodeStart":143,"sourceCodeEnd":179,"githubUrl":"https://github.com/GoogleChrome/lighthouse/blob/9515cd4e58ebed69f78742d932b501c2cab8ad8f/viewer/app/src/lighthouse-report-viewer.js#L143-L179","documentation":"Thrown by the viewer's _validateReportJson when a loaded JSON object has no 'lighthouseVersion' field — the basic marker that a file was produced by Lighthouse. This is the first check in report validation; a missing version short-circuits before the version-comparison logic runs. (Older/lower versions only produce a warning, not this error.)","triggerScenarios":"Loading any JSON file into the viewer that is not a Lighthouse Result — e.g. a random JSON config, a PSI raw response wrapper without a version, a hand-edited object, or the wrong file selected by the user.","commonSituations":"User picks the wrong file; loading a partial/truncated LHR; integrating a JSON source that omits lighthouseVersion.","solutions":["Load a genuine Lighthouse report JSON (it includes lighthouseVersion at the top level).","Pre-validate the file before loading: check json.lighthouseVersion exists.","Show a clear message that the selected file is not a Lighthouse report."],"exampleFix":"// before\nthis._replaceReportHtml(json); // json has no lighthouseVersion\n\n// after\nif (!json?.lighthouseVersion) {\n  logger.error('Selected file is not a Lighthouse report');\n  return;\n}\nthis._validateReportJson(json);\nthis._replaceReportHtml(json);","handlingStrategy":"validation","validationCode":"function isLighthouseReport(json) {\n  return json != null && typeof json === 'object' && typeof json.lighthouseVersion === 'string';\n}\nif (!isLighthouseReport(json)) {\n  logger.error('Selected file is not a Lighthouse report');\n} else {\n  this._validateReportJson(json);\n  this._replaceReportHtml(json);\n}","typeGuard":"/** @param {unknown} j */\nfunction looksLikeLighthouseReport(j) {\n  return j != null && typeof j === 'object' && typeof /** @type {any} */ (j).lighthouseVersion === 'string';\n}","tryCatchPattern":"try {\n  this._validateReportJson(json);\n} catch (err) {\n  if (err.message === 'JSON file was not generated by Lighthouse') {\n    logger.error('This file is not a Lighthouse report.');\n  } else throw err;\n}","preventionTips":["Check for a top-level lighthouseVersion string before loading a JSON file.","Only accept files exported by Lighthouse (CLI --output json or the viewer's save).","Show a clear message when a user selects the wrong file."],"tags":["viewer","validation","lhr","json"],"backgroundTag":null,"analyzedSha":"9515cd4e58ebed69f78742d932b501c2cab8ad8f","analyzedAt":"2026-08-13T06:28:10.346Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}