So, I have a JSON array through which I am looping, and adding three keys and their values, I also want to remove/delete a key(subject_id) from every element in the array.
How to go about doing this?
s=JSON.parse(subjects.to_json)
s.each do |j|
j["total_classes"] = total_classes[i]
j["attended_classes"] = attended_classes[i]
j["subject_name"] = subject_name[i]
j["subject_id"] #remove this key, how?
i=i+1
end
render json: { attendances: s }
Try this one
j.delete("subject_id")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With