Is there a module which can pretty print json format data in Nodejs?

2018-04-15 22:09:16 +08:00
 bluetoy

As the title describe,

Can you help me recomend a module?

thanks!

4222 次点击
所在节点    Node.js
12 条回复
lihongjie0209
2018-04-15 22:33:53 +08:00
yes, a module with thousands of dependency
klesh
2018-04-15 22:36:36 +08:00
JSON.stringify(o, null, 2)
Lxxyx
2018-04-15 22:48:16 +08:00
楼上+1,原生支持
chengluyu
2018-04-15 22:51:14 +08:00
`JSON.stringify` or `require('util').inspect`
SuperMild
2018-04-15 22:54:16 +08:00
Your English is so good, why not search that by yourself?

I just put your title (as it is) into google, just 1 second or less later, the first item of the result is what you want.
ynyounuo
2018-04-15 23:02:04 +08:00
英语不好真的不用硬来,本来就是中文社区。
bluetoy
2018-04-15 23:25:29 +08:00
SuperMild
2018-04-15 23:33:25 +08:00
@bluetoy 原来如此,推荐你一个好方案!在 chrome 里安装 google 输入法插件,在 firefox 里搜一下 pinyin 之类的关键词也有插件的,我就是这样用,系统级别的输入法我就不装了,因为在 linux 里我基本上都是在网页里才需要中文输入法。
autoxbc
2018-04-16 00:07:14 +08:00
http://jsbeautifier.org/
https://www.npmjs.com/package/js-beautify


CLI Options:
-f, --file Input file(s) (Pass '-' for stdin)
-r, --replace Write output in-place, replacing input
-o, --outfile Write output to file (default stdout)
--config Path to config file
--type [js|css|html] ["js"]
-q, --quiet Suppress logging to stdout
-h, --help Show this help
-v, --version Show the version

Beautifier Options:
-s, --indent-size Indentation size [4]
-c, --indent-char Indentation character [" "]
-t, --indent-with-tabs Indent with tabs, overrides -s and -c
-e, --eol Character(s) to use as line terminators.
[first newline in file, otherwise "\n]
-n, --end-with-newline End output with newline
--editorconfig Use EditorConfig to set up the options
-l, --indent-level Initial indentation level [0]
-p, --preserve-newlines Preserve line-breaks (--no-preserve-newlines disables)
-m, --max-preserve-newlines Number of line-breaks to be preserved in one chunk [10]
-P, --space-in-paren Add padding spaces within paren, ie. f( a, b )
-E, --space-in-empty-paren Add a single space inside empty paren, ie. f( )
-j, --jslint-happy Enable jslint-stricter mode
-a, --space-after-anon-function Add a space before an anonymous function's parens, ie. function ()
-b, --brace-style [collapse|expand|end-expand|none][,preserve-inline] [collapse,preserve-inline]
-u, --unindent-chained-methods Don't indent chained method calls
-B, --break-chained-methods Break chained method calls across subsequent lines
-k, --keep-array-indentation Preserve array indentation
-x, --unescape-strings Decode printable characters encoded in xNN notation
-w, --wrap-line-length Wrap lines at next opportunity after N characters [0]
-X, --e4x Pass E4X xml literals through untouched
--good-stuff Warm the cockles of Crockford's heart
-C, --comma-first Put commas at the beginning of new line instead of end
-O, --operator-position Set operator position (before-newline|after-newline|preserve-newline) [before-newline]
Kongtou
2018-04-16 00:11:40 +08:00
haha,interesting
jasonchn
2018-04-16 00:16:13 +08:00
这英文太尬了。。。
bluetoy
2018-04-16 12:17:42 +08:00
@SuperMild 确实有用

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/447056

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX