{"id":16296236,"url":"https://github.com/jannchie/serialize-any-object","last_synced_at":"2026-01-26T22:46:15.201Z","repository":{"id":224338888,"uuid":"763030955","full_name":"Jannchie/serialize-any-object","owner":"Jannchie","description":null,"archived":false,"fork":false,"pushed_at":"2024-10-24T02:03:29.000Z","size":97,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-21T12:01:44.774Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jannchie.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-02-25T11:27:58.000Z","updated_at":"2024-10-24T02:03:33.000Z","dependencies_parsed_at":null,"dependency_job_id":"74d0668f-e923-455a-8ba2-0b4a526dc070","html_url":"https://github.com/Jannchie/serialize-any-object","commit_stats":null,"previous_names":["jannchie/serialize-any-object"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jannchie%2Fserialize-any-object","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jannchie%2Fserialize-any-object/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jannchie%2Fserialize-any-object/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jannchie%2Fserialize-any-object/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jannchie","download_url":"https://codeload.github.com/Jannchie/serialize-any-object/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406029,"owners_count":20933803,"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-10-10T20:21:47.580Z","updated_at":"2026-01-26T22:46:15.169Z","avatar_url":"https://github.com/Jannchie.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Serialize Any Object\n\nSerializeAnything is a TypeScript / JavaScript library that provides stringify and parse functions which enable the following features:\n\n- Support for serializing nested objects with circular references.\n- Support for serializing anonymous functions.\n- Support for restoring type information during deserialization.\n\n## Setup\n\n```bash\nnpm install serialize-any-object\n```\n\n## Usage\n\n```typescript\nimport { parse, stringify } from 'serialize-any-object'\n```\n\n## API\n\n### stringify(obj: any): string\n\nSerialize an object into a JSON string.\n\n- obj: The object to be serialized.\n- Return value: The serialized JSON string.\n\n### parse\u003cT\u003e(jsonString: string, typeObj: Map\u003cstring, any\u003e): T\n\nDeserialize a JSON string into an object.\n\n- jsonString: The JSON string to be deserialized.\n- typeObj: A mapping from class names to class constructors.\n- Return value: The deserialized object.\n\n## Example\n\n```typescript\nimport { parse, stringify } from 'serialize-any-object'\n\nclass Library {\n  books: Book[] = []\n  toString() {\n    return `Library with ${this.books.length} books`\n  }\n\n  addBook(book: Book) {\n    book.library = this\n    this.books.push(book)\n  }\n\n  findMethod: (library: Library) =\u003e Book | undefined = library =\u003e library.books[0]\n}\n\n// This is a circular reference: books have a reference to library and library has a reference to books\n// This is a problem for JSON.stringify, but not for our stringify function\nclass Book {\n  library: Library | null = null\n  constructor(public title: string, public author: string) {}\n  toString() {\n    return `${this.title} by ${this.author}`\n  }\n}\n\n// This is a lambda function.\n// Normally, it is impossible to serialize functions. But our's can.\nconst findTheGreatGatsby = (library: Library) =\u003e library.books.find(book =\u003e book.title === 'The Great Gatsby')\n\nconst library = new Library()\nlibrary.findMethod = findTheGreatGatsby\n\nlibrary.addBook(\n  new Book('The Catcher in the Rye', 'J.D. Salinger'),\n)\nlibrary.addBook(\n  new Book('The Great Gatsby', 'F. Scott Fitzgerald'),\n)\n\nconst libraryString = stringify(library)\n// In general, the serialized json does not contain class information.\n// But our's does. You should add a map of class names to class constructors.\nconst libraryParsed = parse\u003cLibrary\u003e(libraryString, { Library, Book })\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjannchie%2Fserialize-any-object","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjannchie%2Fserialize-any-object","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjannchie%2Fserialize-any-object/lists"}