It sounds like you're doing something like this:
// Create an array
var a = [];
// Add an entry to it
a[0] = "I'm an array entry";
// Add a non-entry property to it
a.foo = "bar";
// Convert to JSON
var json = JSON.stringify(a);
...and finding that the string doesn't have the foo property.
That's correct. JSON's arrays don't support arbitrary non-entry properties the way JavaScript's arrays do, and so they get silently dropped during serialization (the same way properties with the value undefined or referring to functions do).
The answer is not to do that if you need to go through JSON.
But, the structure you quoted later in your question doesn't do that, and can readily be created like this:
var data = [
[
{
"name": "Breakfast",
"value": "buffalo strip ",
"check": 0
},
{
"name": "snack ",
"value": "pecan pie butter",
"check": 0
},
{
"name": "dessert",
"value": "chocolate zucchani brownie",
"check": 0
}
],
[
{
"name": "Breakfast",
"value": "Stir Fried Kale and Baccon ",
"check": 1
},
{
"name": "snack ",
"value": "Smoked Salmon nori roll "
},
{
"name": "dessert",
"value": "Apple muffins"
}
]
];
var json = JSON.stringify(data);
That structure is (from the outside in): An array containing two entries, each of which is another array; within each array, you have a series of objects, which have properties.
I don't know why you want to have the two arrays inside the outermost array, but that's what the structure showed.
If you meant just a single array, that would look like this if you were creating it all at once:
var data = [
{
"name": "Breakfast",
"value": "buffalo strip ",
"check": 0
},
{
"name": "snack ",
"value": "pecan pie butter",
"check": 0
},
{
"name": "dessert",
"value": "chocolate zucchani brownie",
"check": 0
},
{
"name": "Breakfast",
"value": "Stir Fried Kale and Baccon ",
"check": 1
},
{
"name": "snack ",
"value": "Smoked Salmon nori roll "
},
{
"name": "dessert",
"value": "Apple muffins"
}
];
var json = JSON.stringify(data);
...or if building it up over time:
var data = [];
data.push({
name: "Breakfast",
value: "buffalo strip ",
check: 0
});
data.push({
name: "snack ",
value: "pecan pie butter",
check: 0
});
// ...
var json = JSON.stringify(data);