Last active
March 13, 2019 22:43
-
-
Save mhluska/ea2ee0195fc12b69fed52af697932134 to your computer and use it in GitHub Desktop.
No circular reference
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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