One thing about ruby that I love (or hate) that we can literally read it aloud on conversation language and programmatically still working.

3.times do
  # something

However for handling json type, we should noted that "quoted text" actually valid json format therefore we can’t casually write s.to_json to convert text to json object but instead use JSON.parse()

s = '{"hello": "world"}'

# Wrong
# Output => "\"{\\\"hello\\\": \\\"world\\\"}\""

# Right
# Output => {"hello"=>"world"}

m = {hello: 'world'}

# Right
# Output => "{\"hello\":\"world\"}"

Conclusion: Use .to_json if the variable is map. Use JSON.parse() if the variable is string. The same thing with .to_s and JSON.generate()