Skip to content

Instantly share code, notes, and snippets.

@mhluska
Last active March 13, 2019 22:43
Show Gist options
  • Save mhluska/ea2ee0195fc12b69fed52af697932134 to your computer and use it in GitHub Desktop.
Save mhluska/ea2ee0195fc12b69fed52af697932134 to your computer and use it in GitHub Desktop.
No circular reference
const util = require('util')
norm_widget_1 = {
'foo': 1,
'bar': 'baz',
'_jv': {
'type': 'widget',
'id': '1',
'relationships': {
'widgets': {
'data': {
'type': 'widget',
'id': '2'
},
'links': {
'related': '/widget/1/widgets'
}
}
}
}
}
norm_widget_2 = {
'foo': 2,
'_jv': {
'type': 'widget',
'id': '2',
'relationships': {
'widgets': {
'data': [
{
'type': 'widget',
'id': '1'
},
{
'type': 'widget',
'id': '3'
}
]
}
}
}
}
norm_widget_1_rels = JSON.parse(JSON.stringify(norm_widget_1))
norm_widget_1_rels['_jv']['rels'] = { 'widgets': norm_widget_2 }
console.log(util.inspect(norm_widget_1_rels, { showHidden: false, depth: null }))
// Output:
// { foo: 1,
// bar: 'baz',
// _jv:
// { type: 'widget',
// id: '1',
// relationships:
// { widgets:
// { data: { type: 'widget', id: '2' },
// links: { related: '/widget/1/widgets' } } },
// rels:
// { widgets:
// { foo: 2,
// _jv:
// { type: 'widget',
// id: '2',
// relationships:
// { widgets:
// { data: [ { type: 'widget', id: '1' }, { type: 'widget', id: '3' } ] } } } } } } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment