{"id":13469649,"url":"https://github.com/storybookjs/telejson","last_synced_at":"2025-09-18T23:29:27.246Z","repository":{"id":33177550,"uuid":"154148194","full_name":"storybookjs/telejson","owner":"storybookjs","description":"🛰 JSON parse \u0026 stringify with support for cyclic objects, functions, dates, regex, infinity, undefined, null, NaN, Classes, Instances","archived":false,"fork":false,"pushed_at":"2023-08-21T06:38:53.000Z","size":1685,"stargazers_count":169,"open_issues_count":14,"forks_count":28,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-29T21:01:08.514Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/storybookjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null}},"created_at":"2018-10-22T13:23:40.000Z","updated_at":"2024-09-10T16:05:28.000Z","dependencies_parsed_at":"2023-02-10T04:30:24.818Z","dependency_job_id":"ae305384-0ccb-4247-888d-49c5c5744b84","html_url":"https://github.com/storybookjs/telejson","commit_stats":{"total_commits":162,"total_committers":25,"mean_commits":6.48,"dds":0.3765432098765432,"last_synced_commit":"d4d6cd0574a7d866e082e4f964c9e34c0d8ee037"},"previous_names":[],"tags_count":39,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storybookjs%2Ftelejson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storybookjs%2Ftelejson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storybookjs%2Ftelejson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/storybookjs%2Ftelejson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/storybookjs","download_url":"https://codeload.github.com/storybookjs/telejson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222121829,"owners_count":16934973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T15:01:48.574Z","updated_at":"2025-09-18T23:29:27.200Z","avatar_url":"https://github.com/storybookjs.png","language":"TypeScript","funding_links":[],"categories":["JavaScript","TypeScript","🛠️ Developer Tools"],"sub_categories":[],"readme":"# TeleJSON\n\nA library for teleporting rich data to another place.\n\n## Install\n\n```sh\nyarn add telejson\n```\n\n## What can it do, what can't it do:\n\n`JSON.parse` \u0026 `JSON.stringify` have limitation by design, because there are no data formats for things like\n\n- Date\n- Function\n- Class\n- Symbol\n- Error\n- etc.\n\nAlso JSON doesn't support cyclic data structures.\n\nThis library allows you to pass in data with all of the above properties.\nIt will transform the properties to something that's allowed by the JSON spec whilst stringifying,\nand then convert back to the cyclic data structure when parsing.\n\nWhen parsing, **class instances** will be given the Class's name again.\nThe prototype isn't copied over.\n\n**Functions** are supported, they are stringified and will be eval-ed when called.\nThis lazy eval is important for performance.\nThe eval happens via `eval()`\nFunctions are stripped of comments and whitespace.\n\n\u003e Obviously calling the function will only really work as expected if the functions were pure the begin with.\n\n**Regular expressions** just work.\n\n**Symbol** will be re-created with the same string. (resulting in a similar, but different symbol)\n\n**Dates** are parsed back into actual Date objects.\n\n**DOM Events** are processed to extract the internal (hidden) properties, resulting in an object containing the same properties but not being an instance of the original class.\n\n## API\n\nYou have 2 choices:\n\n```js\nimport { stringify, parse } from 'telejson';\n\nconst Foo = function () {};\n\nconst root = {\n  date: new Date('2018'),\n  regex1: /foo/,\n  regex2: /foo/g,\n  regex2: new RegExp('foo', 'i'),\n  fn1: () =\u003e 'foo',\n  fn2: function fn2() {\n    return 'foo';\n  },\n  Foo: new Foo(),\n};\n\n// something cyclic\nroot.root = root;\n\nconst stringified = stringify(root);\nconst parsed = parse(stringified);\n```\n\nstringify and parse do not conform to the JSON.stringify or JSON.parse api.\nthey take an data object and a option object.\n\nOR you can use use the `replacer` and `reviver`:\n\n```js\nimport { replacer, reviver } from 'telejson';\nimport data from 'somewhere';\n\nconst stringified = JSON.stringify(data, replacer(), 2);\nconst parsed = JSON.parse(stringified, reviver(), 2);\n```\n\nnotice that both replacer and reviver need to be called! doing the following will NOT WORK:\n\n```\nconst stringified = JSON.stringify(data, replacer, 2);\nconst parsed = JSON.parse(stringified, reviver, 2);\n```\n\n## options\n\nYou either pass the options-object to `replacer` or as a second argument to `stringify`:\n\n```js\nreplacer({ maxDepth: 10 });\nstringify(date, { maxDepth: 10 });\n```\n\n### replacer\n\n`maxDepth`: controls how deep to keep stringifying. When max depth is reach,\nobjects will be replaced with `\"[Object]\"`, arrays will be replaced with `\"[Array(\u003clength\u003e)]\"`.\ndefault value is `10`\nThis option is really useful if your object is huge/complex, and you don't care about the deeply nested data.\n\n`space`: controls how to prettify the output string.\ndefault value is `undefined`, no white space is used.\nOnly relevant when using `stringify`.\n\n`allowFunction`: When set to false, functions will not be serialized. (default = true)\n\n`allowRegExp`: When set to false, regular expressions will not be serialized. (default = true)\n\n`allowError`: When set to false, error instances will not be serialized. (default = true)\n\n`allowDate`: When set to false, Date objects will not be serialized. (default = true)\n\n`allowUndefined`: When set to false, `undefined` will not be serialized. (default = true)\n\n`allowSymbol`: When set to false, Symbols will not be serialized. (default = true)\n\n## Requirements\n\n`telejson` depends on the collection type `Map`. If you support older browsers and devices which may not yet provide these natively (e.g. IE \u003c 11) or which have non-compliant implementations (e.g. IE 11), consider including a global polyfill in your bundled application, such as `core-js` or `babel-polyfill`.\n\n## Contributing\n\nIf you have any suggestions, please open an issue.\n\nAll contributions are welcome!\n\n### run tests:\n\nfirst, build the package:\n\n```sh\nyarn build\n```\n\nthen run the tests:\n\n```sh\nyarn test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstorybookjs%2Ftelejson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstorybookjs%2Ftelejson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstorybookjs%2Ftelejson/lists"}