title: How to assign serial count in json array using Ruby?
body: <p>I want to assign serial counting to JSON array using ruby. Here is my example JSON</p>
  <pre><code>{
      &quot;product_name&quot; : &quot;Prod 1&quot;,
      &quot;product_description&quot; : &quot;Prod Description 1&quot;,
      &quot;product_id&quot; : &quot;111&quot;,
      &quot;product_attribute&quot; : [{
              &quot;name&quot; : &quot;Size&quot;,
              &quot;value&quot; : &quot;10 mm&quot;
          }, {
              &quot;name&quot; : &quot;Color&quot;,
              &quot;value&quot; : &quot;Red&quot;
          }, {
              &quot;name&quot; : &quot;Width&quot;,
              &quot;value&quot; : &quot;25 mm&quot;
          }, {
              &quot;name&quot; : &quot;Length&quot;,
              &quot;value&quot; : &quot;60 mm&quot;
          }
      ]
  }
  </code></pre>
  <p>My expected result is as how to assign a new key will count the array of product attribute and assign value dynamically</p>
  <pre><code>{
      &quot;product_name&quot; : &quot;Prod 1&quot;,
      &quot;product_description&quot; : &quot;Prod Description 1&quot;,
      &quot;product_id&quot; : &quot;111&quot;,
      &quot;product_attribute&quot; : [{
              &quot;name&quot; : &quot;Size&quot;,
              &quot;value&quot; : &quot;10 mm&quot;,
              &quot;key_num&quot; : 1
          }, {
              &quot;name&quot; : &quot;Color&quot;,
              &quot;value&quot; : &quot;Red&quot;,
              &quot;key_num&quot; : 2
          }, {
              &quot;name&quot; : &quot;Width&quot;,
              &quot;value&quot; : &quot;25 mm&quot;,
              &quot;key_num&quot; : 3
          }, {
              &quot;name&quot; : &quot;Length&quot;,
              &quot;value&quot; : &quot;60 mm&quot;,
              &quot;key_num&quot; : 4
          }
      ]
  }
  </code></pre>
  <p>In the above you can see i added &quot;key_num&quot; 1 to 4. I can have product attribute sometimes as 5,10,8 etc. and i need to assign those &quot;key_num&quot; dynamically based on count of product_attribute</p>