{"id":27268757,"url":"https://github.com/dogusteknoloji/circular-ref-fix","last_synced_at":"2025-04-11T11:32:20.677Z","repository":{"id":57198953,"uuid":"122596167","full_name":"DogusTeknoloji/circular-ref-fix","owner":"DogusTeknoloji","description":":ferris_wheel: Fixes circular dependencies using $id identifiers and $ref pointers. Produces Json.NET friendly result.","archived":false,"fork":false,"pushed_at":"2018-05-04T12:12:48.000Z","size":69,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-22T08:17:33.945Z","etag":null,"topics":["circular","javascript","json"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/DogusTeknoloji.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-02-23T08:48:48.000Z","updated_at":"2024-07-29T16:35:17.000Z","dependencies_parsed_at":"2022-09-16T14:50:58.557Z","dependency_job_id":null,"html_url":"https://github.com/DogusTeknoloji/circular-ref-fix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DogusTeknoloji%2Fcircular-ref-fix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DogusTeknoloji%2Fcircular-ref-fix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DogusTeknoloji%2Fcircular-ref-fix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DogusTeknoloji%2Fcircular-ref-fix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DogusTeknoloji","download_url":"https://codeload.github.com/DogusTeknoloji/circular-ref-fix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248384023,"owners_count":21094657,"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":["circular","javascript","json"],"created_at":"2025-04-11T11:31:59.743Z","updated_at":"2025-04-11T11:32:20.665Z","avatar_url":"https://github.com/DogusTeknoloji.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# circular-ref-fix\n\n[![Build Status](https://travis-ci.org/DogusTeknoloji/circular-ref-fix.svg?branch=master)](https://travis-ci.org/DogusTeknoloji/circular-ref-fix)\n[![Coverage Status](https://coveralls.io/repos/github/DogusTeknoloji/circular-ref-fix/badge.svg?branch=master)](https://coveralls.io/github/DogusTeknoloji/circular-ref-fix?branch=master)\n[![npm version](https://badge.fury.io/js/circular-ref-fix.svg)](https://badge.fury.io/js/circular-ref-fix)\n\n:ferris_wheel: Fixes circular dependencies using $id identifiers and $ref pointers. Produces Json.NET friendly result.\n\n---\n## Usage\n\nLet's model Simpsons family (Maggie hasn't born yet),\n\n```JavaScript\n    var child1 = {\n        name: 'Bart'\n    };\n    var child2 = {\n        name: 'Lisa'\n    };\n    var mother = {\n        name: 'Marge'\n    };\n    var father = {\n        name: 'Homer'\n    };\n\n    child1.siblings = [child2];\n    child1.mother = mother;\n    child1.father = father;\n\n    child2.siblings = [child1];\n    child2.mother = mother;\n    child2.father = father;\n\n    mother.spouse = father;\n    mother.children = [child1, child2];\n\n    father.spouse = mother;\n    father.children = [child1, child2];\n    \n    JSON.stringify([mother, father]); // error! could not serialize\n```\nWe create referential links between objects;\n\n```JavaScript\nvar circularFix = require('circular-ref-fix');\nvar createRefs = circularFix.createRefs;\n\nvar fixed = createRefs(couple);\n```\nProduces below object;\n```JavaScript\n[  \n   {  \n      \"$id\":\"1\",\n      \"name\":\"Marge\",\n      \"spouse\":{  \n         \"$id\":\"2\",\n         \"name\":\"Homer\",\n         \"spouse\":{  \n            \"$ref\":\"1\"\n         },\n         \"children\":[  \n            {  \n               \"$id\":\"3\",\n               \"name\":\"Bart\",\n               \"siblings\":[  \n                  {  \n                     \"$id\":\"4\",\n                     \"name\":\"Lisa\",\n                     \"siblings\":[  \n                        {  \n                           \"$ref\":\"3\"\n                        }\n                     ],\n                     \"mother\":{  \n                        \"$ref\":\"1\"\n                     },\n                     \"father\":{  \n                        \"$ref\":\"2\"\n                     }\n                  }\n               ],\n               \"mother\":{  \n                  \"$ref\":\"1\"\n               },\n               \"father\":{  \n                  \"$ref\":\"2\"\n               }\n            },\n            {  \n               \"$ref\":\"4\"\n            }\n         ]\n      },\n      \"children\":[  \n         {  \n            \"$ref\":\"3\"\n         },\n         {  \n            \"$ref\":\"4\"\n         }\n      ]\n   },\n   {  \n      \"$ref\":\"2\"\n   }\n]\n```\nAlso, we can restore circular structure back;\n\n```JavaScript\nvar circularFix = require('circular-ref-fix');\nvar restored = restoreRefs(fixed, true); // with true option, we tell restoreRefs to delete $id fields\n```\n\nJson.NET can handle this structure too;\n\n```CSharp\nvar settings = new JsonSerializerSettings {\n    PreserveReferencesHandling = PreserveReferencesHandling.Objects\n};\n\nJsonConvert.DeserializeObject\u003cList\u003cParent\u003e\u003e(fixedStr, settings);\n```\n---\n### Node installation and usage\n\n```JavaScript\nnpm i circular-ref-fix\n\nvar circularFix = require('circular-ref-fix');\n```\n\n---\nBecause we are using UMD pattern, you can use the *circular-fix.js* file on browser with script tag or Require.JS.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdogusteknoloji%2Fcircular-ref-fix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdogusteknoloji%2Fcircular-ref-fix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdogusteknoloji%2Fcircular-ref-fix/lists"}