I have been working with a JavaScript object that contains nested objects with associative arrays. I attempted to use the stringify function from the json2.js library, but the output did not include the arrays inside the nested objects. In my scenario, I begin with the following structure:
obj = {"arr1" : [], "arr2" : [], "arr3" : []};
Then, I populate each of the arrays within the object through loops like this:
obj[arr*].push[arritem*];
obj[arr*][arritem*] = something;
The placeholders arr* and arritem* are used in place of the actual variables utilized in the loops. When I utilize Json.stringify(obj), the resulting string is:
'{"arr1" : [0], "arr2" : [0], "arr3" : [0]}'
I desire the output to look more like this:
'{"arr1" : [ "arritem1" : something, "arritem2" : something2], "arr2" : [ "arritem1" : something, "arritem2" : something2], "arr3" : [ "arritem1" : something, "arritem2" : something2]}'
Is there an alternative library or any additional steps required before using stringify?