{"record":{"id":"2dd3701b3b001f3e","repo":"apify/crawlee","slug":"data-item-s-is-not-serializable-to-json-cause","errorCode":null,"errorMessage":"Data item${s}is not serializable to JSON.\nCause: ${err.message}","messagePattern":"Data item(.+?)is not serializable to JSON\\.\nCause: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/core/src/storages/dataset.ts","lineNumber":48,"sourceCode":" * (not an array, not a primitive, not circular).\n *\n * @param item The value to validate.\n * @param index Optional index for error messages when validating inside an array.\n * @ignore\n */\nexport function assertJsonSerializable<T>(item: T, index?: number): void {\n    const s = typeof index === 'number' ? ` at index ${index} ` : ' ';\n    const isItemObject = item && typeof item === 'object' && !Array.isArray(item);\n\n    if (!isItemObject) {\n        throw new Error(`Data item${s}is not an object. You can push only objects into a dataset.`);\n    }\n\n    try {\n        JSON.stringify(item);\n    } catch (e) {\n        const err = e as Error;\n        throw new Error(`Data item${s}is not serializable to JSON.\\nCause: ${err.message}`);\n    }\n}\n\nexport interface DatasetDataOptions {\n    /**\n     * Number of array elements that should be skipped at the start.\n     * @default 0\n     */\n    offset?: number;\n\n    /**\n     * Maximum number of array elements to return.\n     * @default 250000\n     */\n    limit?: number;\n\n    /**\n     * If `true` then the objects are sorted by `createdAt` in descending order.","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/apify/crawlee/blob/dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c/packages/core/src/storages/dataset.ts#L30-L66","documentation":"assertJsonSerializable() also probe-serializes each item with JSON.stringify; if that throws (circular references, BigInt, functions), pushData fails with this error including the underlying cause's message.","triggerScenarios":"pushData({ a }) where a is a BigInt, a cyclic object graph, or an object containing functions/symbols that stringify throws on.","commonSituations":"Scraped objects retaining parent/child references (cycles), passing Playwright/Page values holding BigInts, or embedding class instances with non-serializable fields.","solutions":["Remove circular references before pushing (e.g. by picking only needed fields).","Convert BigInt to string/number, Dates to ISO strings, Maps/Sets to arrays/objects.","Use a safe replacer, e.g. JSON.parse(JSON.stringify(item, replacer)), to normalize.","Push only plain objects built from explicitly selected fields."],"exampleFix":"// before\nawait dataset.pushData({ user, meta: new Map([['k','v']]) });\n\n// after\nawait dataset.pushData({ user, meta: Object.fromEntries(metaMap) });","handlingStrategy":"validation","validationCode":"const safeItem = JSON.parse(JSON.stringify(item, (_k, v) => typeof v === 'bigint' ? v.toString() : v));\nawait dataset.pushData(safeItem);","typeGuard":null,"tryCatchPattern":"try {\n    await dataset.pushData(item);\n} catch (e) {\n    if (e instanceof Error && e.message.includes('not serializable to JSON')) {\n        await dataset.pushData(JSON.parse(JSON.stringify(item, safeReplacer)));\n    } else throw e;\n}","preventionTips":["Break circular references before pushing (store ids, not object graphs).","Convert BigInt, Date, Map, Set, and functions to JSON-friendly values.","Probe with JSON.stringify in a try/catch during development."],"tags":["dataset","json","serialization"],"backgroundTag":"json-serialization-failed","analyzedSha":"dbe57fb09ca607ad59dcf998f3925ef9ac3bb26c","analyzedAt":"2026-08-30T22:22:28.328Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}