Been wracking my brain and googling like mad, but perhaps I'm not searching with the right keywords.
Got a list/array/JSON serialized data (doesn't really matter at this point) like so:
{
"program": 1,
"program": 2,
"program": 3
}
and I'm receiving a series of JSON objects over a node-based socket.io that looks something like this:
{ "program": 1, "sequence_number": 1 }
{ "program": 3, "sequence_number": 2 }
{ "program": 3, "sequence_number": 1 }
{ "program": 2, "sequence_number": 2 }
{ "program": 2, "sequence_number": 1 }
{ "program": 2, "sequence_number": 3 }
And what I am having trouble figuring out is to be able to push/inject/merge this incoming JSON (one at a time as they are received) into my list above to create the following:
{
"program": 1,
{
"sequence_number": 1
},
"program": 2,
{
"sequence_number": 2,
"sequence_number": 1,
"sequence_number": 3
},
"program": 3,
{
"sequence_number": 2,
"sequence_number": 1
}
}
It's one of those things that is akin to being "on the tip of the tongue" but have reached a wall. So I appeal to the community for some tidbits of wisdom, favored solutions, or pointing in the right direction with any known related tutorials. Thanks in advance!
Update 08.Oct.2016
To address comments regarding the bad format of my list, how about a restructuring of the data, like so:
{
"program": 1,
"sequence_list":
[
{ "sequence_number": 1 },
{ "sequence_number": 2 }
]
},
{
"program": 2,
"sequence_list":
[
{ "sequence_number": 1 },
{ "sequence_number": 3 },
{ "sequence_number": 2 }
]
}
... etc.
Does that make more sense?