{"record":{"id":"8a9331fbf5a6a16c","repo":"gatsbyjs/gatsby","slug":"unable-to-parse-json-hint","errorCode":null,"errorMessage":"Unable to parse JSON: ${hint}","messagePattern":"Unable to parse JSON: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/gatsby-transformer-json/src/gatsby-node.js","lineNumber":55,"sourceCode":"    }\n    if (obj.id) {\n      jsonNode[`jsonId`] = obj.id\n    }\n    await createNode(jsonNode)\n    createParentChildLink({ parent: node, child: jsonNode })\n  }\n\n  const { createNode, createParentChildLink } = actions\n\n  const content = await loadNodeContent(node)\n  let parsedContent\n  try {\n    parsedContent = JSON.parse(content)\n  } catch {\n    const hint = node.absolutePath\n      ? `file ${node.absolutePath}`\n      : `in node ${node.id}`\n    throw new Error(`Unable to parse JSON: ${hint}`)\n  }\n\n  if (_.isArray(parsedContent)) {\n    for (let i = 0, l = parsedContent.length; i < l; i++) {\n      const obj = parsedContent[i]\n\n      await transformObject(\n        obj,\n        createNodeId(`${node.id} [${i}] >>> JSON`),\n        getType({ node, object: obj, isArray: true })\n      )\n    }\n  } else if (_.isPlainObject(parsedContent)) {\n    await transformObject(\n      parsedContent,\n      createNodeId(`${node.id} >>> JSON`),\n      getType({ node, object: parsedContent, isArray: false })\n    )","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/gatsbyjs/gatsby/blob/8b06340921ffdf23125a365b9c9923690cb62ce6/packages/gatsby-transformer-json/src/gatsby-node.js#L37-L73","documentation":"Thrown by gatsby-transformer-json's onCreateNode when JSON.parse fails on content loaded from a node whose mediaType is 'application/json'. Gatsby reads the raw file content and attempts to parse it into a JavaScript object to create GraphQL nodes; if the content is syntactically invalid JSON, the parse throws and this error wraps it with a hint identifying the offending file path or node id.","triggerScenarios":"A file with .json extension (or any source plugin node with mediaType 'application/json') contains a syntax error: trailing commas, unquoted keys, single-quoted strings, comments, or truncated/corrupt content. The error fires during 'gatsby build' or 'gatsby develop' in the source/transform node phase.","commonSituations":"JSON files with comments (e.g. tsconfig-style JSON), single-quoted strings inherited from JS config files, BOM characters, trailing commas from hand-editing, files partially written by a CMS or CI pipeline, or a non-JSON file (e.g. .json5, .jsonc) being picked up because the source plugin sets mediaType to application/json.","solutions":["Open the file path reported in the hint and run it through a JSON validator (e.g. `node -e \"JSON.parse(require('fs').readFileSync('PATH','utf8'))\"`) to locate the exact syntax error.","Fix the JSON syntax: remove comments, use double quotes for keys and string values, remove trailing commas, ensure no unescaped control characters.","If the file intentionally uses JSON5/JSONC, configure the source plugin to not set mediaType to 'application/json', or pre-process the file into valid JSON before Gatsby reads it.","If the file is generated by a CMS or external process, ensure the write completes atomically before the Gatsby build starts."],"exampleFix":"// before (broken data.json)\n{\n  'title': 'Hello', // single quotes + comment\n  'items': [1, 2,],\n}\n// after\n{\n  \"title\": \"Hello\",\n  \"items\": [1, 2]\n}","handlingStrategy":"validation","validationCode":"// Validate JSON before Gatsby processes it (pre-build script)\nconst fs = require('fs')\nconst path = require('path')\n\nfunction validateJsonFiles(dir) {\n  for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n    const full = path.join(dir, entry.name)\n    if (entry.isDirectory()) validateJsonFiles(full)\n    else if (entry.name.endsWith('.json')) {\n      try {\n        JSON.parse(fs.readFileSync(full, 'utf8'))\n      } catch (e) {\n        console.error(`Invalid JSON in ${full}: ${e.message}`)\n        process.exit(1)\n      }\n    }\n  }\n}\nvalidateJsonFiles('src/data')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run a JSON lint step in CI before `gatsby build`.","Use a JSON schema validator if your data files follow a known structure.","Avoid hand-editing large JSON files — use a formatter that catches syntax errors.","If using JSONC/JSON5, configure the source plugin's mediaType or pre-convert to standard JSON."],"tags":["json","transformer","build-time","data-parsing","gatsby-transformer-json"],"backgroundTag":null,"analyzedSha":"8b06340921ffdf23125a365b9c9923690cb62ce6","analyzedAt":"2026-08-13T02:36:21.405Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}