title: How can I iterate a JSON object in a rails controller?
body: <p>I'm passing the following data set to my controller in JSON format:</p>
  
  <pre><code>[
      {id: 0, exercises: [15, 18]},
      {id: 1, exercises: [33, 35]} 
  ]
  </code></pre>
  
  <p>This is received in my controller where I have to following code to display it temporarily:</p>
  
  <pre><code>arr = params["_json"]
  binding.pry
  </code></pre>
  
  <p>This gives me the following output in the pry console:</p>
  
  <pre><code>[3] pry(#&lt;ProgramsController&gt;)&gt; arr
  =&gt; [&lt;ActionController::Parameters {"id"=&gt;0, "exercises"=&gt;[16, 7, 18]} permitted: false&gt;,
  &lt;ActionController::Parameters {"id"=&gt;1, "exercises"=&gt;[14, 15]} permitted: false&gt;]
  </code></pre>
  
  <p>I can then iterate this by going through arr[0] and arr[1], but how do I get the exercises that lie within these indexes?</p>
  
  <p>So I can do something like this.</p>
  
  <pre><code>arr.each do |x|
    prog = Program.create(x ...)
    x.each do |exercise|
      prog.exercises.create(exercise_id: exercise.id)
    end
  end
  </code></pre>
  
  <p>Hope someone can help me out handling this data. Thanks!</p>