{"id":12128,"library":"teleport-javascript","title":"Teleport JavaScript Object (De)serialization","description":"Teleport JavaScript is a specialized utility for the deep serialization and deserialization of JavaScript objects, extending far beyond the capabilities of the native `JSON.stringify` and `JSON.parse` methods. Currently stable at version 1.0.0, this library provides robust handling for a wide array of data types including `Date`, `BigInt`, `RegExp`, `Symbol`, `Set`, `Map`, `Buffer`, `undefined`, and all Typed Arrays (e.g., `Int8Array`, `Float64Array`). A key differentiator is its ability to correctly manage circular references within objects, preventing common serialization errors. While a specific release cadence isn't published, its current version suggests a focus on stability for its comprehensive feature set. It positions itself as a 'super light and fast' alternative for scenarios where standard JSON falls short, making it suitable for inter-process communication, storage, or deep cloning of complex JavaScript data structures. It prioritizes covering edge cases and modern JavaScript types for complete object graph preservation.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/codenirvana/teleport-javascript","tags":["javascript","JSON","circular","cyclic","stringify","parse","serialization","date","bigint","typescript"],"install":[{"cmd":"npm install teleport-javascript","lang":"bash","label":"npm"},{"cmd":"yarn add teleport-javascript","lang":"bash","label":"yarn"},{"cmd":"pnpm add teleport-javascript","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For ESM environments, use named imports. CommonJS `require` is also supported.","wrong":"const {parse, stringify} = require('teleport-javascript');","symbol":"parse, stringify","correct":"import { parse, stringify } from 'teleport-javascript';"},{"note":"For CommonJS environments, use destructuring assignment with `require`.","wrong":"import { parse, stringify } from 'teleport-javascript';","symbol":"parse, stringify","correct":"const { parse, stringify } = require('teleport-javascript');"},{"note":"The library exports named functions, not a default export. Use `* as` for grouping if preferred.","wrong":"import teleport from 'teleport-javascript';","symbol":"teleport","correct":"import * as teleport from 'teleport-javascript';"}],"quickstart":{"code":"import { parse, stringify } from 'teleport-javascript';\n\nconst obj = {\n  key: 'value',\n  undefined: undefined,\n  regex: /a-z/gi,\n  set: new Set([-Infinity, NaN, Infinity]),\n  bigint: 900719925474099123n,\n  symbol: Symbol('key'),\n  date: new Date()\n};\nobj.circular = obj; // Add a circular reference\n\nconsole.log('Original object:', obj);\n\nconst stringified = stringify(obj);\nconsole.log('\\nStringified output:', stringified);\n\nconst parsed = parse(stringified);\nconsole.log('\\nParsed object:', parsed);\n\n// Verify circular reference is re-established\nconsole.log('Are circular references restored?', parsed.circular === parsed);\n// Verify BigInt and Date types\nconsole.log('BigInt type preserved?', typeof parsed.bigint === 'bigint');\nconsole.log('Date type preserved?', parsed.date instanceof Date);","lang":"typescript","description":"Demonstrates basic usage of `stringify` and `parse` for a complex object including `BigInt`, `RegExp`, `Set`, `Symbol`, `Date`, `undefined`, and circular references."},"warnings":[{"fix":"If exact `Symbol` reference preservation is critical, consider alternative strategies like passing `Symbol`s out-of-band or using a different serialization approach specifically designed for reference tracking beyond object graphs.","message":"When a `Symbol` is serialized and then deserialized, `teleport-javascript` creates a *new* `Symbol` with the same description, rather than preserving the original `Symbol` reference. This is standard behavior for serialization, but important to note if strict reference equality for `Symbol`s is expected.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Avoid deserializing input from untrusted sources. If absolutely necessary, sanitize or validate inputs rigorously before passing them to `parse`, and implement robust error handling and resource limits.","message":"As with any custom deserialization library, parsing stringified data from untrusted sources carries inherent security risks. While `teleport-javascript` reconstructs objects without executing arbitrary code, specially crafted malicious input could potentially lead to unexpected object structures, resource exhaustion, or other application-specific vulnerabilities.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Understand the full list of supported types and how they are handled. If strict `JSON.stringify` behavior is needed for a subset of the data, use `JSON.stringify` directly on that subset.","message":"`teleport-javascript` extends `JSON.stringify`'s capabilities by supporting types like `undefined`, `BigInt`, and `Set` which `JSON.stringify` either omits or throws on. Users expecting strict JSON-compliant output or the default `JSON.stringify` behavior (e.g., omitting `undefined` properties) should be aware of these differences.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change `const {parse, stringify} = require('teleport-javascript');` to `import { parse, stringify } from 'teleport-javascript';`","cause":"Attempting to use CommonJS `require()` syntax within an ES Module (type: 'module' in package.json or .mjs file).","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"Ensure you are using named imports: `import { parse, stringify } from 'teleport-javascript';` or `const { parse, stringify } = require('teleport-javascript');`","cause":"Attempting to call `stringify()` or `parse()` directly after a default import, or if the named imports were missed in destructuring.","error":"TypeError: stringify is not a function"},{"fix":"Use `teleport-javascript`'s `stringify` function instead: `const stringified = stringify(objWithBigInt);`","cause":"Trying to serialize an object containing a `BigInt` using the native `JSON.stringify()` method, which does not support `BigInt`s by default.","error":"TypeError: Cannot convert a BigInt value to a JSON string"}],"ecosystem":"npm"}