13

I want to import my CSV file to my database, my CSV file has following string and I need to parse it to a Ruby array object, how to do that?

"[\"Mt Roskill\", \"Sylvia Park\"]"
0

1 Answer 1

22

That example string looks like JSON. Use JSON.parse to return a Ruby array:

require 'json'

JSON.parse("[\"Mt Roskill\", \"Sylvia Park\"]")
#=> ["Mt Roskill", "Sylvia Park"]
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.