Вводя команду node
из командной строки, узел запускает REPL . Из этого REPL, есть ли способ хорошенькой печати JSON?
Например: с Bash:
Now using node v12.14.1 (npm v6.13.6)
:~/Code/tmp$ node
Начинает REPL:
Welcome to Node.js v12.14.1.
Type ".help" for more information.
> msg = { "hello":"world", "quantity": 1 }
Выполнение JSON.stringify(msg)
производит:
'{"hello":"world","quantity":1}'
Выполнение JSON.stringify(msg, null, 2)
производит:
'{\n "hello": "world",\n "quantity": 1\n}'
Что я хочу:
{
"hello": "world",
"quantity": 1
}