JSON: How to add dynamic sub objects to dynamically created main object in Json.

kumar_bsc
Kilo Explorer

var mainObj = [

  {

  name: 'someName',

  some_data: [

  {

  someOtherName: 'Some',

  someOtherNum: '112'

  },

  {

  someOtherName: 'A2325A',

  someOtherNum: '132'

  }

  ]

  },

  {

  name: 'someName1',

  some_data: [

  {

  someOtherName: 'Some',

  someOtherNum: '112'

  },

  {

  someOtherName: 'A2325A',

  someOtherNum: '132'

  }

  ]

  }

]

This particular content is hard coded, I want this to be generated dynamically from an array where all this data is being stored. Can this be done?

5 REPLIES 5

Muthu,



I don't know of a way to get your array name (subNames) to be the same as the property name in the object. There may be a crafty way to do it in JavaScript, but I just don't know at this point. Perhaps there is someone else who can help.



Have you checked stackoverflow.com? This appears to be more of a JavaScript question (which they are very good at) rather than a ServiceNow question.