How to convert nested objects to json in ruby?
For example, an object obj contains a custom instance variable b
If you use to_json, the content of b cannot be output.
What is needed is the output of obj.to_s, but if it is in the form of json
It is possible to use to_yaml, but I hope to convert it directly to json
By the way, to_json and to_yaml are obviously the same function. Why is there such a difference in results?
Output: