How to merge these arrays/json objects?
<p>I am a bit confused at this point on what is an object, what is an array, and what is a JSON.  Can someone explain the differences in syntax between the two? and how to add items to each, how to merge each type, and such?  I am trying to get this function to take the new information from a JSON object (I think) and merge it with some new information.  This information will then be passed to a PHP script to be processed.</p>

<p>Here is the console output:</p>

<pre><code>{"public":{"0":["el29t7","3bmGDy"]}} 
{"public":"[object Object][object Object]"} 
</code></pre>

<p>Here is the JS I am using:</p>

<pre><code>/* Helper function to clean up any current data we have stored */
function insertSerializedData(ids, type) {
    // Get anything in the current field
    current_data = $('#changes').val();
    if (!current_data) {
        var data = {};
        data[index++] = ids;
        var final_data = {};
        final_data[type] = data;
        $('#changes').val(JSON.stringify(final_data));
    } else {
        current_data = JSON.parse(current_data);
        var data = {};
        data[index++] = ids;
        // Does the index exist?
        if (type in current_data) {
            var temp_data = current_data[type];
            current_data[type] = temp_data + data;
        } else {
            current_data[type] = data;
        }
        //var extra_data = {};
        //extra_data[type] = data;
        //$.merge(current_data, extra_data);
        $('#changes').val(JSON.stringify(current_data));
    }
    console.log($('#changes').val());
}
</code></pre>

<p>The idea is if the key (public, or whatever other ones) doesn't exist yet, then to make it point to an array of arrays.  If it does exist though, then that of array of arrays need to be merged with a new array.  For instance:</p>

<p>If I have  </p>

<pre><code>{"public":{"0":["el29t7","3bmGDy"]}}  
</code></pre>

<p>and I want to merge it with </p>

<pre><code>["aj19vA", "jO71Ba"] 
</code></pre>

<p>then final result would be:</p>

<pre><code>{"public":{"0":["el29t7","3bmGDy"], "1":["aj19vA", "jO71Ba"]}} 
</code></pre>

<p>How can i go about doing this?  Thanks</p>
