{"record":{"id":"ee286606ea955d9c","repo":"GoogleChrome/lighthouse","slug":"provided-json-is-not-a-lighthouse-result","errorCode":null,"errorMessage":"provided json is not a Lighthouse result","messagePattern":"provided json is not a Lighthouse result","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"treemap/app/src/main.js","lineNumber":985,"sourceCode":"   * Accepts if json is an lhr, or {lhr: ...} or {lighthouseResult: ...}\n   * Throws error if json does not match expectations.\n   * @param {any} json\n   * @return {LH.Treemap.Options}\n   */\n  coerceToOptions(json) {\n    /** @type {LH.Treemap.Options['lhr']|null} */\n    let lhr = null;\n    if (json && typeof json === 'object') {\n      for (const maybeLhr of [json, json.lhr, json.lighthouseResult]) {\n        if (maybeLhr?.audits && typeof maybeLhr.audits === 'object') {\n          lhr = maybeLhr;\n          break;\n        }\n      }\n    }\n\n    if (!lhr) {\n      throw new Error('provided json is not a Lighthouse result');\n    }\n\n    if (!lhr.audits['script-treemap-data']) {\n      throw new Error('provided Lighthouse result is missing audit: `script-treemap-data`');\n    }\n\n    let initialView;\n    if (json && typeof json === 'object' && typeof json.initialView === 'string') {\n      initialView = json.initialView;\n    }\n\n    return {lhr, initialView};\n  }\n\n  /**\n   * Loads report json from gist URL, if valid. Updates page URL with gist id\n   * and loads from GitHub.\n   * @param {string} urlStr gist URL","sourceCodeStart":967,"sourceCodeEnd":1003,"githubUrl":"https://github.com/GoogleChrome/lighthouse/blob/9515cd4e58ebed69f78742d932b501c2cab8ad8f/treemap/app/src/main.js#L967-L1003","documentation":"Thrown by the treemap app's coerceToOptions when none of the candidate shapes — the JSON itself, json.lhr, or json.lighthouseResult — has an 'audits' object. The treemap accepts a raw LHR, a runner-result wrapper ({lhr:...}), or a PSI-style wrapper ({lighthouseResult:...}), and requires at minimum an 'audits' object to be considered a Lighthouse result.","triggerScenarios":"Loading arbitrary/wrong JSON into the treemap: passing a plain object, a settings file, or a payload whose audits were stripped. None of the three inspected keys yields an object with an 'audits' property.","commonSituations":"User drops the wrong file onto the treemap; URL hash carries malformed/truncated JSON; integrating treemap with a custom JSON source that doesn't match the expected LHR shape.","solutions":["Load an actual Lighthouse Result (or wrap it as {lhr: lhr} / {lighthouseResult: lhr}).","Validate the payload has a top-level or nested 'audits' object before passing it to the treemap.","Surface a user-friendly message when the input fails this shape check."],"exampleFix":"// before\ntreemapApp.load(jsonFromFile); // arbitrary json\n\n// after\nfunction looksLikeLhr(x) {\n  return x && typeof x === 'object' && x.audits && typeof x.audits === 'object';\n}\nconst candidate = looksLikeLhr(json) ? json\n  : looksLikeLhr(json?.lhr) ? json.lhr\n  : looksLikeLhr(json?.lighthouseResult) ? json.lighthouseResult\n  : null;\nif (candidate) treemapApp.load(candidate); else showInvalidFileError();","handlingStrategy":"type-guard","validationCode":"function asLhr(json) {\n  const candidates = [json, json?.lhr, json?.lighthouseResult];\n  return candidates.find(c => c && typeof c === 'object' && c.audits && typeof c.audits === 'object') ?? null;\n}\nconst lhr = asLhr(json);\nif (!lhr) throw new Error('Input is not a Lighthouse result');","typeGuard":"/** @param {any} x */\nfunction looksLikeLhr(x) {\n  return x != null && typeof x === 'object' && typeof x.audits === 'object' && x.audits !== null;\n}","tryCatchPattern":"try {\n  treemapApp.load(json);\n} catch (err) {\n  if (err.message === 'provided json is not a Lighthouse result') {\n    showInvalidFileError();\n  } else throw err;\n}","preventionTips":["Validate the JSON has an 'audits' object (directly or under lhr/lighthouseResult) before loading into the treemap.","Accept the documented wrappers ({lhr}, {lighthouseResult}) but normalize to the raw LHR first.","Show a clear error when a user supplies the wrong file."],"tags":["treemap","validation","lhr","json"],"backgroundTag":null,"analyzedSha":"9515cd4e58ebed69f78742d932b501c2cab8ad8f","analyzedAt":"2026-08-13T06:28:10.346Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}