I have a JSON array with ActiveRecord objects. These objects can be reconstructed using the from_json method, which every AR object has. However with from_json it’s only possible to reconstruct one single object.
To process an array, I could of course just extract substrings from the JSON array and create every object from it’s own substring in a loop or so. However I’m wondering if there is a better way to do this, without string manipulation involved.
I would do
After that just
and do
or
what fits better for you.
Both of these methods return Ruby data structure that corresponds to the json structure. So, if you have a json array of obejcts, after JSON.load or JSON.parse you’ll get Ruby array of hashes. You should’t have any problems to manipulate this kind of structure.