
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
json-populate
Advanced tools
Tool for populating JSON data with infinitely recursive circular references. Sort of like Falcor, but for plain JSON.
Tool 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)
Populating by naming convention:
/**
* Import lib
*/
const { populateByConvention } = require('json-populate');
/**
* Example data
*/
const stories = [
{
type: 'story',
id: 'story-1',
author: {
person: 'person-1',
},
},
{
type: 'story',
id: 'story-2',
author: {
person: 'person-2',
},
},
];
const people = [
{
type: 'person',
id: 'person-1',
name: 'John Storywriter',
authored: {
stories: ['story-1'],
},
likes: {
stories: [
'story-1',
'story-2',
],
}
},
{
type: 'person',
id: 'person-2',
name: 'Peter Telltale',
authored: {
stories: ['story-2'],
},
likes: {
stories: [
'story-1',
'story-2',
],
}
}
];
/**
* Consolidate the collections into a "graph"
*/
const graph = { people, stories };
/**
* Choose an entry point to the graph
*/
const entry = people[0];
/**
* Create a populated entry point resolved against the graph with a specified depth
*/
const populatedItem = populateByConvention(2, graph, entry);
/**
* Result
*/
console.log(JSON.stringify(populatedItem, null, 2));
/**
* {
* "type": "person",
* "id": "person-1",
* "name": "John Storywriter",
* "authored": {
* "stories": [
* {
* "type": "story",
* "id": "story-1",
* "author": {
* "person": {
* "type": "person",
* "id": "person-1",
* "name": "John Storywriter",
* "authored": {
* "stories": [
* "story-1"
* ]
* },
* "likes": {
* "stories": [
* "story-1",
* "story-2"
* ]
* }
* }
* }
* }
* ]
* },
* "likes": {
* "stories": [
* {
* "type": "story",
* "id": "story-1",
* "author": {
* "person": {
* "type": "person",
* "id": "person-1",
* "name": "John Storywriter",
* "authored": {
* "stories": [
* "story-1"
* ]
* },
* "likes": {
* "stories": [
* "story-1",
* "story-2"
* ]
* }
* }
* }
* },
* {
* "type": "story",
* "id": "story-2",
* "author": {
* "person": {
* "type": "person",
* "id": "person-2",
* "name": "Peter Telltale",
* "authored": {
* "stories": [
* "story-2"
* ]
* },
* "likes": {
* "stories": [
* "story-1",
* "story-2"
* ]
* }
* }
* }
* }
* ]
* }
* }
*/
Populating by explicit reference:
/**
* Import lib
*/
const { populateByReference } = require('json-populate');
/**
* Example data
*/
const stories = [
{
type: 'story',
id: 'story-1',
author: { $ref: 'people', id: 'person-1' }
},
{
type: 'story',
id: 'story-2',
author: { $ref: 'people', id: 'person-2' }
},
];
const people = [
{
type: 'person',
id: 'person-1',
name: 'John Storywriter',
authored: [
{ $ref: 'stories', id: 'story-1' },
],
likes: [
{ $ref: 'stories', id: 'story-1' },
{ $ref: 'stories', id: 'story-2' },
],
},
{
type: 'person',
id: 'person-2',
name: 'Peter Telltale',
authored: [
{ $ref: 'stories', id: 'story-2' },
],
likes: [
{ $ref: 'stories', id: 'story-1' },
{ $ref: 'stories', id: 'story-2' },
],
}
];
/**
* Consolidate the collections into a "graph"
*/
const graph = { people, stories };
/**
* Choose an entry point to the graph
*/
const entry = people[0];
/**
* Create a populated entry point resolved against the graph with a specified depth
*/
const populatedItem = populateByReference(2, graph, entry);
/**
* Result
*/
console.log(JSON.stringify(populatedItem, null, 2));
/**
* {
* "type": "person",
* "id": "person-1",
* "name": "John Storywriter",
* "authored": [
* {
* "type": "story",
* "id": "story-1",
* "author": {
* "type": "person",
* "id": "person-1",
* "name": "John Storywriter",
* "authored": [
* {
* "$ref": "stories",
* "id": "story-1"
* }
* ],
* "likes": [
* {
* "$ref": "stories",
* "id": "story-1"
* },
* {
* "$ref": "stories",
* "id": "story-2"
* }
* ]
* }
* }
* ],
* "likes": [
* {
* "type": "story",
* "id": "story-1",
* "author": {
* "type": "person",
* "id": "person-1",
* "name": "John Storywriter",
* "authored": [
* {
* "$ref": "stories",
* "id": "story-1"
* }
* ],
* "likes": [
* {
* "$ref": "stories",
* "id": "story-1"
* },
* {
* "$ref": "stories",
* "id": "story-2"
* }
* ]
* }
* },
* {
* "type": "story",
* "id": "story-2",
* "author": {
* "type": "person",
* "id": "person-2",
* "name": "Peter Telltale",
* "authored": [
* {
* "$ref": "stories",
* "id": "story-2"
* }
* ],
* "likes": [
* {
* "$ref": "stories",
* "id": "story-1"
* },
* {
* "$ref": "stories",
* "id": "story-2"
* }
* ]
* }
* }
* ]
* }
*/
FAQs
Tool for populating JSON data with infinitely recursive circular references. Sort of like Falcor, but for plain JSON.
The npm package json-populate receives a total of 6 weekly downloads. As such, json-populate popularity was classified as not popular.
We found that json-populate demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.