{"record":{"id":"b50b23ba6aa7a21e","repo":"BabylonJS/Babylon.js","slug":"invalid-json-from-string-spritesheet-managed-with","errorCode":null,"errorMessage":"Invalid JSON from string. Spritesheet managed with constant cell size.","messagePattern":"Invalid JSON from string\\. Spritesheet managed with constant cell size\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/Sprites/spriteManager.ts","lineNumber":421,"sourceCode":"                        if (typeof Object.keys(_f)[0] !== \"string\") {\r\n                            throw new Error(\"Invalid JSON Format.  Check the frame values and make sure the name is the first parameter.\");\r\n                        }\r\n\r\n                        const name: string = _f[Object.keys(_f)[0]];\r\n                        frametemp[name] = _f;\r\n                    }\r\n                    celldata.frames = frametemp;\r\n                }\r\n\r\n                const spritemap = <string[]>Reflect.ownKeys(celldata.frames);\r\n\r\n                this._spriteMap = spritemap;\r\n                this._packedAndReady = true;\r\n                this._cellData = celldata.frames;\r\n            } catch (e) {\r\n                this._fromPacked = false;\r\n                this._packedAndReady = false;\r\n                throw new Error(\"Invalid JSON from string. Spritesheet managed with constant cell size.\", { cause: e });\r\n            }\r\n        } else {\r\n            const re = /\\./g;\r\n            let li: number;\r\n            do {\r\n                li = re.lastIndex;\r\n                re.test(imgUrl);\r\n            } while (re.lastIndex > 0);\r\n            const jsonUrl = imgUrl.substring(0, li - 1) + \".json\";\r\n            const onerror = () => {\r\n                Logger.Error(\"JSON ERROR: Unable to load JSON file.\");\r\n                this._fromPacked = false;\r\n                this._packedAndReady = false;\r\n            };\r\n            const onload = (data: string | ArrayBuffer) => {\r\n                try {\r\n                    const celldata = JSON.parse(data as string);\r\n                    const spritemap = <string[]>Reflect.ownKeys(celldata.frames);\r","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/Sprites/spriteManager.ts#L403-L439","documentation":"In SpriteManager's packed mode (_makePacked), the constructor parses a JSON string describing the spritesheet's frames/cells. If JSON.parse fails or the parsed object does not have the expected shape (e.g. no frames array), the manager flags itself as unpacked and throws this error so the caller knows the spritesheet falls back to constant-cell-size assumptions. The library throws because a malformed spritemap makes per-frame cell data unreliable.","triggerScenarios":"Calling new SpriteManager(...) with a packed spritemap JSON string that is syntactically invalid JSON, or valid JSON whose frames/animation data does not match the documented packed format (missing .frames).","commonSituations":"Hand-edited spritemap JSON, fetching the JSON with a tool that returned HTML/error pages instead of JSON, using an atlas exported from a tool with an unsupported format (e.g. non-TexturePacker layout), or trimming/encoding steps that corrupted the string before passing it to the manager.","solutions":["Validate the JSON string with JSON.parse and inspect the frames property before constructing the SpriteManager","Re-export the spritesheet using the format documented for packed SpriteManager input","Ensure you are passing the actual JSON content (not a URL) when using the packed string API","Log the underlying cause (e.cause) to see the exact JSON.parse syntax error"],"exampleFix":"// before\nconst sm = new SpriteManager(name, textureUrl, capacity, spriteJSONString);\n// after\nlet parsed;\ntry {\n  parsed = JSON.parse(spriteJSONString);\n} catch (e) {\n  parsed = null;\n}\nif (!parsed || !parsed.frames) {\n  console.error('Spritesheet JSON malformed, using constant cell size');\n}\nconst sm = new SpriteManager(name, textureUrl, capacity, spriteJSONString);","handlingStrategy":"validation","validationCode":"function isValidPackedJson(s: string): boolean {\n  try { const o = JSON.parse(s); return !!o && typeof o.frames !== 'undefined'; }\n  catch { return false; }\n}\nif (!isValidPackedJson(spriteJSONString)) throw new Error('bad spritemap JSON');","typeGuard":"function isPackedSheet(v: unknown): v is { frames: unknown[] } {\n  return typeof v === 'object' && v !== null && Array.isArray((v as any).frames);\n}","tryCatchPattern":"try {\n  new SpriteManager(name, texUrl, capacity, spriteJSONString);\n} catch (e) {\n  console.error('spritemap JSON invalid:', (e as Error).cause);\n  // fall back to constant cell size manager\n}","preventionTips":["JSON.parse and inspect .frames before constructing the manager","Export atlases only in the documented format","Never pass an HTML error page body as the JSON string","Log e.cause to capture the precise JSON syntax problem"],"tags":["json","spritesheet","parsing"],"backgroundTag":"invalid-json-atlas","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}