title: How can I set my data as JSON in a hidden input field
body: <p>I have an input field like the one below</p>
  
  <pre><code> &lt;input type="hidden" value="" id="inputField"&gt;
  </code></pre>
  
  <p>Now I have list of products and for each product I have a checkbox. When a user clicks on the checkbox, I get the product id and name. Now I want to save it again in the hidden field  like below</p>
  
  <pre><code>&lt;input type="hidden" 
         value="[{"product_id":123,"name":"stack"},{"product_id":456,"name":"overflow"}]"
         id="inputField"
  &gt;
  </code></pre>
  
  <p>My first question is how I can do this and how can I create the JSON?</p>
  
  <p>Secondly if the user again unchecks a product checkbox then I need to get the current hidden value and convert it into some data structure, remove the unchecked box id from the data structure and then save it again in the hidden field. </p>
  
  <p>Is there any library which does this job in JavaScript?</p>