I have an output from an API that look like this… (its a string)
[[2121212,212121,asd],[2323232,23232323,qasdasd]]
Its a string – not an array. I want to convert it to an array and then extract the first two elements in each array in the nested array to:
[2121212,212121],[2323232,23232323]
What’s the best way to do this ruby? I could use regexp and extract – but basically the string is already an array, however the class is a string.
I tried
array.push(response)
but that just put the string in to the array as one element. I guess what would be nice is a to_array method
Assuming this is a JSON response (and if so, it is badly malformed and you should talk to the people that are responsible for this) you could write something like:
this prints