Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. const util = require('util')
  2.  
  3. norm_widget_1 = {
  4. 'foo': 1,
  5. 'bar': 'baz',
  6. '_jv': {
  7. 'type': 'widget',
  8. 'id': '1',
  9. 'relationships': {
  10. 'widgets': {
  11. 'data': {
  12. 'type': 'widget',
  13. 'id': '2'
  14. },
  15. 'links': {
  16. 'related': '/widget/1/widgets'
  17. }
  18. }
  19. }
  20. }
  21. }
  22.  
  23. norm_widget_2 = {
  24. 'foo': 2,
  25. '_jv': {
  26. 'type': 'widget',
  27. 'id': '2',
  28. 'relationships': {
  29. 'widgets': {
  30. 'data': [
  31. {
  32. 'type': 'widget',
  33. 'id': '1'
  34. },
  35. {
  36. 'type': 'widget',
  37. 'id': '3'
  38. }
  39. ]
  40. }
  41. }
  42. }
  43. }
  44.  
  45. norm_widget_1_rels = JSON.parse(JSON.stringify(norm_widget_1))
  46. norm_widget_1_rels['_jv']['rels'] = { 'widgets': norm_widget_2 }
  47.  
  48. console.log(util.inspect(norm_widget_1_rels, { showHidden: false, depth: null }))
  49.  
  50. // Output:
  51. // { foo: 1,
  52. // bar: 'baz',
  53. // _jv:
  54. // { type: 'widget',
  55. // id: '1',
  56. // relationships:
  57. // { widgets:
  58. // { data: { type: 'widget', id: '2' },
  59. // links: { related: '/widget/1/widgets' } } },
  60. // rels:
  61. // { widgets:
  62. // { foo: 2,
  63. // _jv:
  64. // { type: 'widget',
  65. // id: '2',
  66. // relationships:
  67. // { widgets:
  68. // { data: [ { type: 'widget', id: '1' }, { type: 'widget', id: '3' } ] } } } } } } }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement