{"record":{"id":"8242218ce02adc7e","repo":"BabylonJS/Babylon.js","slug":"unexpected-json-chunk","errorCode":null,"errorMessage":"Unexpected JSON chunk","messagePattern":"Unexpected JSON chunk","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/loaders/src/glTF/glTFFileLoader.pure.ts","lineNumber":1354,"sourceCode":"\r\n        // Bail if there are no other chunks.\r\n        if (dataReader.byteOffset + chunkLength === length) {\r\n            return dataReader.loadAsync(chunkLength).then(() => {\r\n                return { json: this._parseJson(dataReader.readString(chunkLength)), bin: null };\r\n            });\r\n        }\r\n\r\n        // Read the JSON chunk and the length and type of the next chunk.\r\n        return dataReader.loadAsync(chunkLength + 8).then(() => {\r\n            const data: IGLTFLoaderData = { json: this._parseJson(dataReader.readString(chunkLength)), bin: null };\r\n\r\n            const readAsync = (): Promise<IGLTFLoaderData> => {\r\n                const chunkLength = dataReader.readUint32();\r\n                const chunkFormat = dataReader.readUint32();\r\n\r\n                switch (chunkFormat) {\r\n                    case ChunkFormat.JSON: {\r\n                        throw new Error(\"Unexpected JSON chunk\");\r\n                    }\r\n                    case ChunkFormat.BIN: {\r\n                        const startByteOffset = dataReader.byteOffset;\r\n                        data.bin = {\r\n                            readAsync: (byteOffset, byteLength) => dataReader.buffer.readAsync(startByteOffset + byteOffset, byteLength),\r\n                            byteLength: chunkLength,\r\n                        };\r\n                        dataReader.skipBytes(chunkLength);\r\n                        break;\r\n                    }\r\n                    default: {\r\n                        // ignore unrecognized chunkFormat\r\n                        dataReader.skipBytes(chunkLength);\r\n                        break;\r\n                    }\r\n                }\r\n\r\n                if (dataReader.byteOffset !== length) {\r","sourceCodeStart":1336,"sourceCodeEnd":1372,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/loaders/src/glTF/glTFFileLoader.pure.ts#L1336-L1372","documentation":"Thrown in the v2 chunk loop when a chunk with format ChunkFormat.JSON is encountered after the first (JSON) chunk. The glb spec allows only one JSON chunk, and it must be first; a second one is invalid.","triggerScenarios":"Loading a .glb containing two JSON chunks — e.g. a concatenation of files or a custom writer duplicating the metadata chunk.","commonSituations":"Naive merge scripts appending two glbs; buggy chunk-splitting tools; corrupted multi-chunk files.","solutions":["Rebuild the .glb with a single JSON chunk followed by BIN chunk(s) using glTF-Transform","Remove the duplicate/extra JSON chunk from the container","Validate with glTF-Validator; re-export from the original source asset"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"function countJsonChunks(buf) {\n  const dv = new DataView(buf);\n  let off = 20, count = 0;\n  while (off + 8 <= dv.byteLength) {\n    const len = dv.getUint32(off, true), fmt = dv.getUint32(off + 4, true);\n    if (fmt === 0x4e4f534a) count++;\n    off += 8 + len;\n  }\n  return count;\n}\nif (countJsonChunks(await file.arrayBuffer()) > 1) throw new Error('Duplicate JSON chunk');","typeGuard":null,"tryCatchPattern":"try {\n  await loader.loadAsync(url);\n} catch (e) {\n  if (e.message === 'Unexpected JSON chunk') {\n    console.error('glb contains a second JSON chunk — rebuild the container');\n  }\n}","preventionTips":["Never concatenate .glb files byte-wise; merge assets with glTF-Transform instead","Scan chunk lists in your ingestion pipeline for duplicate JSON chunks","Validate with glTF-Validator before deployment"],"tags":["gltf","binary","file-format"],"backgroundTag":"invalid-file-magic","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}