title: Create custom JSON string from form
body: <p>I have a form I'd like to submit as JSON via jQuery AJAX, so that I can read it into a temporary table on the server-side using one my programming language's native methods (OpenEdge using READ-JSON). An example of the JSON my form needs to produce is:</p>
  
  <pre><code>{"ttOrder": [
    {
      "cProduct": "prod01",
      "iQty": 123
    },
    {
      "cProduct": "prod02",
      "iQty": 456
    }
  ]}
  </code></pre>
  
  <p>My form is made up of a table containing rows of product information, product code, description etc. and a quantity input field, e.g.</p>
  
  <pre><code>&lt;input id="prod01" name="prod01" value="0"&gt;
  </code></pre>
  
  <p>From searching around Stack Overflow I found a couple of suggestions that looked like they might help, as I think I need to serialise the form:</p>
  
  <pre><code>(function( $ ){
      $.fn.serializeJSON=function() {
          var json = {};
          jQuery.map($(this).serializeArray(), function(n, i){
              json[n['name']] = n['value'];
          });
          return json;
      };
  })( jQuery );
  
  var obj = {"ttOrder": [$('#prodform').serializeJSON() ]};
  </code></pre>
  
  <p>And then in the $.ajax call use</p>
  
  <pre><code>...
  data: JSON.stringify(obj),
  ...
  </code></pre>
  
  <p>However, this gives the following:</p>
  
  <pre><code>{"ttOrder": [
    {
      "prod01": "123",
      "prod02": "456"
    }
  ]}
  </code></pre>
  
  <p>I think that all the code above is doing is creating a JSON string comprising of the input name and value as a key &amp; value pair, but I don't have the know-how to change the code to get me what I require.</p>
  
  <p>I think that what I'm trying to achieve is to have an array of objects where the name of the array is always ttOrder (maps to my temp-table name), the first entry of an object is the product code (always cProduct - maps to my temp-table field name) with a value of the input's name, and the second entry of an object is the quantity (always iQty - maps to my temp-table field value).</p>
  
  <p>Please excuse any incorrect terminology I use.</p>
  
  <p>Thanks.</p>