1

I have this string : data = "[\"super\", \"cool!\", \"bien écrit\", \"first!\", \"why is everyone speaking French here?\"]"

I would like to transform it to be like : data = ["super", "cool!", "bien écrit", "first!", "why is everyone speaking French here?"]

0

2 Answers 2

3

Parse it like a JSON. Try

require 'json'
data = JSON.parse data
Sign up to request clarification or add additional context in comments.

4 Comments

This is actually not Json. It's saved like that Comment.create!( content:["super", "cool!", "bien écrit", "first!", "why is everyone speaking French here?"] ); So when I want to display it it return me a string
So? It's a valid JSON.
@Orsay You show us string in data variable and this string is valid JSON like Ursus say.
You may want to serialize the content attribute : apidock.com/rails/ActiveRecord/AttributeMethods/Serialization/…
1

The data looks like JSON. parse it using JSON.parse(data)

1 Comment

This is actually not Json. It's saved like that Comment.create!( content:["super", "cool!", "bien écrit", "first!", "why is everyone speaking French here?"] ); So when I want to display it it return me a string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.