I make an AJAX request and I get back a response saved to a data variable.
My controller:
def retrieve
  data = params[:data]
  @question = Question.find_by(id: params[:question_id])
  @choices = @question.choices
  results = []
  for d in data
    if Choice.find_by(id: d).correct
      results << d
    end
  end
  respond_to do |format|
    format.json {
      render json: {
        choices: @choices.to_json(only: [:id,:correct]),
        results: results,
        message: "success"
        }
      }
  end
end
The response:
Object {choices: "[{"id":1,"correct":true},{"id":2,"correct":false}]", results: Array[1], message: "success"}
I'm getting value undefined where there should be a value.
data.choices[0].id -> returns undefined
    
as_jsoninstead ofto_json