{"id":18050147,"url":"https://github.com/arshad-yaseen/circular-to-json","last_synced_at":"2026-04-28T20:01:48.933Z","repository":{"id":183444948,"uuid":"620673743","full_name":"arshad-yaseen/circular-to-json","owner":"arshad-yaseen","description":"This library that provides a way to handle circular references when serializing and deserializing JSON objects.","archived":false,"fork":false,"pushed_at":"2023-03-29T18:19:44.000Z","size":33,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-09T13:47:16.814Z","etag":null,"topics":["circular","circular-json","json","json-stringify","string","structure"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/circular-to-json?activeTab=readme","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/arshad-yaseen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":"arshad","tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2023-03-29T06:36:49.000Z","updated_at":"2024-11-26T10:06:02.000Z","dependencies_parsed_at":"2023-07-24T14:47:08.947Z","dependency_job_id":null,"html_url":"https://github.com/arshad-yaseen/circular-to-json","commit_stats":null,"previous_names":["arshad-yaseen/circular-to-json"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/arshad-yaseen/circular-to-json","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arshad-yaseen%2Fcircular-to-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arshad-yaseen%2Fcircular-to-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arshad-yaseen%2Fcircular-to-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arshad-yaseen%2Fcircular-to-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arshad-yaseen","download_url":"https://codeload.github.com/arshad-yaseen/circular-to-json/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arshad-yaseen%2Fcircular-to-json/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32396781,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["circular","circular-json","json","json-stringify","string","structure"],"created_at":"2024-10-30T21:10:46.528Z","updated_at":"2026-04-28T20:01:48.904Z","avatar_url":"https://github.com/arshad-yaseen.png","language":"TypeScript","funding_links":["https://ko-fi.com/arshad"],"categories":[],"sub_categories":[],"readme":"\n#### This library that provides a way to handle circular references when serializing and deserializing JSON objects. When serializing an object that has circular references, the default JSON.stringify() method will throw an error. CircularJSON provides a way to avoid this error by converting circular references to a stringified version of \"[Circular]\".\n\n\n## Installation\n\nYou can install using NPM or Yarn:\n\n```bash\n  npm i circular-to-json\n\n```\n\n```bash\n  yarn add circular-to-json\n\n```\n\n## Simple Usage\n\n#### This package exports a `CircularJSON` object with two methods: `stringify`, `parse` and `stringifyAndParse`. Here's how you can use them:\n\n## Stringify\n\n```javascript\nimport CircularJSON from \"circular-to-json\";\n\nconst obj = { a: 1 };\nobj.b = obj; // adding circular reference\n\nconst jsonString = CircularJSON.stringify(obj);\n\nconsole.log(jsonString);\n```\n\n#### Output\n\n```javascript\n'{\"a\":1,\"b\":{\"[Circular]\":true}}';\n```\n\n## Parse\n\n```javascript\nconst jsonString = CircularJSON.stringify(obj);\nconst parsedObj = CircularJSON.parse(jsonString);\nconsole.log(parsedObj);\n```\n\n#### Output\n\n```javascript\n{ a: 1, b: [Circular] }\n```\n\n## stringifyAndParse\n\n#### `stringifyAndParse` method that combines the `stringify` and `parse` methods into a single operation.\n\n```javascript\nconst obj = { a: 1 };\nobj.b = obj;\n\nconst parsedObj = CircularJSON.stringifyAndParse(obj);\n```\n\n#### Output\n\n```javascript\n{ a: 1, b: [Circular] }\n```\n\n## Other Usage\n\n#### The `stringify` method takes an optional `replacer` function and an optional `space` parameter, which work the same way as the corresponding parameters in `JSON.stringify`.\n\n## stringify - space\n\n```javascript\nconst obj = {\n  name: \"John\",\n  age: 30,\n  hobbies: [\"reading\", \"running\", \"cooking\"],\n  address: {\n    street: \"123 Main St\",\n    city: \"Anytown\",\n    state: \"CA\",\n    zip: \"12345\"\n  }\n};\n\n// Set the space parameter to '\\t' to use a tab for indentation\nconst jsonStrWithTab = CircularJSON.stringify(obj, undefined, '\\t');\nconsole.log(jsonStrWithTab);\n\n```\n\n#### Output\n\n```javascript\n{\n\t\"name\": \"John\",\n\t\"age\": 30,\n\t\"hobbies\": [\n\t\t\"reading\",\n\t\t\"running\",\n\t\t\"cooking\"\n\t],\n\t\"address\": {\n\t\t\"street\": \"123 Main St\",\n\t\t\"city\": \"Anytown\",\n\t\t\"state\": \"CA\",\n\t\t\"zip\": \"12345\"\n\t}\n}\n\n\n```\n\n## stringify - replacer\n\n```javascript\nconst obj = {\n  name: \"Alice\",\n  age: 30,\n  children: [\n    { name: \"Bob\", age: 5 },\n    { name: \"Charlie\", age: 3 },\n  ],\n};\n\n// Define a replacer function that converts all numbers to strings\nconst replacer = (key, value) =\u003e {\n  if (typeof value === \"number\") {\n    return value.toString();\n  }\n  return value;\n};\n\nconst jsonString = CircularJSON.stringify(obj, replacer);\n\nconsole.log(jsonString);\n```\n\n#### Output\n\n```javascript\n{\n  \"name\": \"Alice\",\n  \"age\": \"30\",\n  \"children\": [\n    {\n      \"name\": \"Bob\",\n      \"age\": \"5\"\n    },\n    {\n      \"name\": \"Charlie\",\n      \"age\": \"3\"\n    }\n  ]\n}\n```\n\n## parse - reviver\n\n#### The `parse` method takes an optional `reviver` function, which works the same way as the corresponding parameter in `JSON.parse`.\n\n```javascript\nconst jsonString =\n  '{\"name\":\"John Smith\",\"age\":30,\"car\":{\"model\":\"Tesla\",\"year\":2022}}';\n\nconst reviver = (key, value) =\u003e {\n  if (typeof value === \"string\" \u0026\u0026 key !== \"\") {\n    return value.toUpperCase(); // convert all string values (except the root object) to uppercase\n  }\n  return value; // otherwise return the original value\n};\n\nconst obj = JSON.parse(jsonString, reviver);\n\nconsole.log(obj);\n```\n\n#### Output\n\n```javascript\n{\n  \"name\": \"JOHN SMITH\",\n  \"age\": 30,\n  \"car\": {\n    \"model\": \"TESLA\",\n    \"year\": 2022\n  }\n}\n\n```\n\n### Contributing\n\n#### circular-to-json is an open-source project, and we welcome contributions from the community.\n\n### Licence\n\n#### CircularJSON is licensed under the `MIT License`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farshad-yaseen%2Fcircular-to-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farshad-yaseen%2Fcircular-to-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farshad-yaseen%2Fcircular-to-json/lists"}