JSON: How to add dynamic sub objects to dynamically created main object in Json.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-22-2016 05:30 AM
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?
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2016 06:09 AM
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.