title: Couchapp: how to store a document?
body: <p>after having finished the <a href="http://couchapp.org/page/evently-do-it-yourself-ii-state" rel="nofollow">couchapp tutoria</a>l, the last step from there has to be done: saving the created pizza.</p>
  
  <p>For this I have created a JS function "saveToppings", which is executed (as the firebug console shows) but fails uppon saving my JSON document with the message:</p>
  
  <blockquote>
    <p>The document could not be saved: Document must be a JSON object.</p>
  </blockquote>
  
  <p>So I understand, my doc is no JSON doc, but I don't know how to do this properly.</p>
  
  <p>Here is the code of the "saveToppings" function:</p>
  
  <pre><code>function(e){
  var json_toppings = JSON.stringify($$(this).toppings);
  var merged_toppings = "{ \"type\":\"topping\", \"contents\":" + json_toppings + "}";
  
  $.log('json_toppings: '+ json_toppings.toString());
  
  $.log('merged_toppings: '+ merged_toppings.toString());
  
  $$(this).app.db.saveDoc(merged_toppings, {
      success : function() {
        alert("Doc saved successfully.");
      }
    });
  }
  </code></pre>
  
  <p>...and the debug from the console:</p>
  
  <pre><code>json_toppings: [{"top":"tomatoes"},{"top":"bacon"},{"top":"cheese"}]
  merged_toppings: { "type":"topping", "contents":[{"top":"tomatoes"},{"top":"bacon"},{"top":"cheese"}]}
  </code></pre>