问题:
I would like my JSON output in Ruby on Rails to be "pretty" or nicely formatted. 我希望Ruby on Rails中的JSON输出是“漂亮的”或格式正确的。
Right now, I call to_json
and my JSON is all on one line. 现在,我调用to_json
而我的JSON都在一行上。 At times this can be difficult to see if there is a problem in the JSON output stream. 有时很难发现JSON输出流中是否存在问题。
Is there way to configure or a method to make my JSON "pretty" or nicely formatted in Rails? 有没有方法可以配置我的JSON或在Rails中很好地格式化JSON?
解决方案:
参考一: https://stackoom.com/question/MXd/如何在Ruby-on-Rails中-漂亮-格式化JSON输出参考二: https://oldbug.net/q/MXd/How-can-I-pretty-format-my-JSON-output-in-Ruby-on-Rails
来源:oschina
链接:https://my.oschina.net/u/4438370/blog/4396792