如何在Ruby on Rails中“漂亮”格式化JSON输出?

倾然丶 夕夏残阳落幕 提交于 2020-10-03 03:51:59

问题:

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!