如何通过终端缩进多个 JSON 文件
How to indent multiple JSON files via terminal
有没有一种快速的方法可以通过终端在当前目录下缩进一组给定的 JSON 文件,类似于在 Sublime 文本上使用 "Pretty JSON" 或 "Indent JSON" 插件?
通过 shell 脚本或 python 脚本等?
有python:
echo '{"foo": "bar"}' | python -m json.tool
或jq:
echo '{"foo": "bar"}' | jq .
现在替换目录中的每个 JSON 文件:
ls *.json | xargs -I % sh -c "cat % | python -m json.tool > %.new ; mv %.new %"
有没有一种快速的方法可以通过终端在当前目录下缩进一组给定的 JSON 文件,类似于在 Sublime 文本上使用 "Pretty JSON" 或 "Indent JSON" 插件?
通过 shell 脚本或 python 脚本等?
有python:
echo '{"foo": "bar"}' | python -m json.tool
或jq:
echo '{"foo": "bar"}' | jq .
现在替换目录中的每个 JSON 文件:
ls *.json | xargs -I % sh -c "cat % | python -m json.tool > %.new ; mv %.new %"