{"id":23260260,"url":"https://github.com/eiriklv/json-populate","last_synced_at":"2026-03-16T23:33:45.756Z","repository":{"id":57153888,"uuid":"97383508","full_name":"eiriklv/json-populate","owner":"eiriklv","description":"Tool for populating JSON data with circular references. Sort of like Falcor and GraphQL, but for plain JSON with a transparent interface.","archived":false,"fork":false,"pushed_at":"2022-09-02T20:31:30.000Z","size":13,"stargazers_count":153,"open_issues_count":0,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-10T16:18:32.010Z","etag":null,"topics":[],"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/eiriklv.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":"2017-07-16T13:01:20.000Z","updated_at":"2024-04-02T20:23:06.000Z","dependencies_parsed_at":"2022-09-06T19:21:57.912Z","dependency_job_id":null,"html_url":"https://github.com/eiriklv/json-populate","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/eiriklv%2Fjson-populate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eiriklv%2Fjson-populate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eiriklv%2Fjson-populate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eiriklv%2Fjson-populate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eiriklv","download_url":"https://codeload.github.com/eiriklv/json-populate/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230438244,"owners_count":18225873,"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-12-19T13:14:55.543Z","updated_at":"2026-03-16T23:33:45.727Z","avatar_url":"https://github.com/eiriklv.png","language":"JavaScript","funding_links":[],"categories":["Transformations"],"sub_categories":[],"readme":"JSON-populate\n=============\n\n[![npm version](https://badge.fury.io/js/json-populate.svg)](https://badge.fury.io/js/json-populate)\n\nTool for populating JSON data with infinitely recursive circular references. Sort of like Falcor, but for plain JSON. It uses `Proxy` to lazily resolve relations where supported, otherwise there's a polyfill that uses an eager `Object.assign` approach (slow and very memory intensive if you populate more than a few levels - it's really just there for symbolic backwards compatibility)\n\n## Usage examples\n\nPopulating by naming convention:\n\n```js\n/**\n * Import lib\n */\nconst { populateByConvention } = require('json-populate');\n\n/**\n * Example data\n */\nconst stories = [\n  {\n    type: 'story',\n    id: 'story-1',\n    author: {\n      person: 'person-1',\n    },\n  },\n  {\n    type: 'story',\n    id: 'story-2',\n    author: {\n      person: 'person-2',\n    },\n  },\n];\n\nconst people = [\n  {\n    type: 'person',\n    id: 'person-1',\n    name: 'John Storywriter',\n    authored: {\n      stories: ['story-1'],\n    },\n    likes: {\n      stories: [\n        'story-1',\n        'story-2',\n      ],\n    }\n  },\n  {\n    type: 'person',\n    id: 'person-2',\n    name: 'Peter Telltale',\n    authored: {\n      stories: ['story-2'],\n    },\n    likes: {\n      stories: [\n        'story-1',\n        'story-2',\n      ],\n    }\n  }\n];\n\n/**\n * Consolidate the collections into a \"graph\"\n */\nconst graph = { people, stories };\n\n/**\n * Choose an entry point to the graph\n */\nconst entry = people[0];\n\n/**\n * Create a populated entry point resolved against the graph with a specified depth\n */\nconst populatedItem = populateByConvention(2, graph, entry);\n\n/**\n * Result\n */\nconsole.log(JSON.stringify(populatedItem, null, 2));\n\n/**\n * {\n *   \"type\": \"person\",\n *   \"id\": \"person-1\",\n *   \"name\": \"John Storywriter\",\n *   \"authored\": {\n *     \"stories\": [\n *       {\n *         \"type\": \"story\",\n *         \"id\": \"story-1\",\n *         \"author\": {\n *           \"person\": {\n *             \"type\": \"person\",\n *             \"id\": \"person-1\",\n *             \"name\": \"John Storywriter\",\n *             \"authored\": {\n *               \"stories\": [\n *                 \"story-1\"\n *               ]\n *             },\n *             \"likes\": {\n *               \"stories\": [\n *                 \"story-1\",\n *                 \"story-2\"\n *               ]\n *             }\n *           }\n *         }\n *       }\n *     ]\n *   },\n *   \"likes\": {\n *     \"stories\": [\n *       {\n *         \"type\": \"story\",\n *         \"id\": \"story-1\",\n *         \"author\": {\n *           \"person\": {\n *             \"type\": \"person\",\n *             \"id\": \"person-1\",\n *             \"name\": \"John Storywriter\",\n *             \"authored\": {\n *               \"stories\": [\n *                 \"story-1\"\n *               ]\n *             },\n *             \"likes\": {\n *               \"stories\": [\n *                 \"story-1\",\n *                 \"story-2\"\n *               ]\n *             }\n *           }\n *         }\n *       },\n *       {\n *         \"type\": \"story\",\n *         \"id\": \"story-2\",\n *         \"author\": {\n *           \"person\": {\n *             \"type\": \"person\",\n *             \"id\": \"person-2\",\n *             \"name\": \"Peter Telltale\",\n *             \"authored\": {\n *               \"stories\": [\n *                 \"story-2\"\n *               ]\n *             },\n *             \"likes\": {\n *               \"stories\": [\n *                 \"story-1\",\n *                 \"story-2\"\n *               ]\n *             }\n *           }\n *         }\n *       }\n *     ]\n *   }\n * }\n */\n```\n\nPopulating by explicit reference:\n\n```js\n/**\n * Import lib\n */\nconst { populateByReference } = require('json-populate');\n\n/**\n * Example data\n */\nconst stories = [\n  {\n    type: 'story',\n    id: 'story-1',\n    author: { $ref: 'people', id: 'person-1' }\n  },\n  {\n    type: 'story',\n    id: 'story-2',\n    author: { $ref: 'people', id: 'person-2' }\n  },\n];\n\nconst people = [\n  {\n    type: 'person',\n    id: 'person-1',\n    name: 'John Storywriter',\n    authored: [\n      { $ref: 'stories', id: 'story-1' },\n    ],\n    likes: [\n      { $ref: 'stories', id: 'story-1' },\n      { $ref: 'stories', id: 'story-2' },\n    ],\n  },\n  {\n    type: 'person',\n    id: 'person-2',\n    name: 'Peter Telltale',\n    authored: [\n      { $ref: 'stories', id: 'story-2' },\n    ],\n    likes: [\n      { $ref: 'stories', id: 'story-1' },\n      { $ref: 'stories', id: 'story-2' },\n    ],\n  }\n];\n\n/**\n * Consolidate the collections into a \"graph\"\n */\nconst graph = { people, stories };\n\n/**\n * Choose an entry point to the graph\n */\nconst entry = people[0];\n\n/**\n * Create a populated entry point resolved against the graph with a specified depth\n */\nconst populatedItem = populateByReference(2, graph, entry);\n\n/**\n * Result\n */\nconsole.log(JSON.stringify(populatedItem, null, 2));\n\n/**\n * {\n *   \"type\": \"person\",\n *   \"id\": \"person-1\",\n *   \"name\": \"John Storywriter\",\n *   \"authored\": [\n *     {\n *       \"type\": \"story\",\n *       \"id\": \"story-1\",\n *       \"author\": {\n *         \"type\": \"person\",\n *         \"id\": \"person-1\",\n *         \"name\": \"John Storywriter\",\n *         \"authored\": [\n *           {\n *             \"$ref\": \"stories\",\n *             \"id\": \"story-1\"\n *           }\n *         ],\n *         \"likes\": [\n *           {\n *             \"$ref\": \"stories\",\n *             \"id\": \"story-1\"\n *           },\n *           {\n *             \"$ref\": \"stories\",\n *             \"id\": \"story-2\"\n *           }\n *         ]\n *       }\n *     }\n *   ],\n *   \"likes\": [\n *     {\n *       \"type\": \"story\",\n *       \"id\": \"story-1\",\n *       \"author\": {\n *         \"type\": \"person\",\n *         \"id\": \"person-1\",\n *         \"name\": \"John Storywriter\",\n *         \"authored\": [\n *           {\n *             \"$ref\": \"stories\",\n *             \"id\": \"story-1\"\n *           }\n *         ],\n *         \"likes\": [\n *           {\n *             \"$ref\": \"stories\",\n *             \"id\": \"story-1\"\n *           },\n *           {\n *             \"$ref\": \"stories\",\n *             \"id\": \"story-2\"\n *           }\n *         ]\n *       }\n *     },\n *     {\n *       \"type\": \"story\",\n *       \"id\": \"story-2\",\n *       \"author\": {\n *         \"type\": \"person\",\n *         \"id\": \"person-2\",\n *         \"name\": \"Peter Telltale\",\n *         \"authored\": [\n *           {\n *             \"$ref\": \"stories\",\n *             \"id\": \"story-2\"\n *           }\n *         ],\n *         \"likes\": [\n *           {\n *             \"$ref\": \"stories\",\n *             \"id\": \"story-1\"\n *           },\n *           {\n *             \"$ref\": \"stories\",\n *             \"id\": \"story-2\"\n *           }\n *         ]\n *       }\n *     }\n *   ]\n * }\n */\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feiriklv%2Fjson-populate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feiriklv%2Fjson-populate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feiriklv%2Fjson-populate/lists"}