不要从缩小 json 的“值”中删除白色 space

Don't remove white space from `value` in minified json

一些支持者 :- 我不能使用 jq 或其他 python/ruby 解决方案,我只能使用 bash (POSIX)

我有以下格式的 json :-

{
    "argumets": {
        "arg1": "-write -nrFiles 1000 -size1000",
        "arg2": "-read -nrFiles 1000 -size1000",
        "arg3": "-clean"
    }
}

我正在使用这个 tr 命令来缩小 json :-

tr -d '[:space:]' < input_json.file > output_json.file

这是我得到的输出:-

{"argumets":{"arg1":"-write-nrFiles1000-size1000","arg2":"-read-nrFiles1000-size1000","arg3":"-clean"}}

这里我在 value 一边失去 space 像 -write-nrFiles1000-size1000

我可以做些什么来避免上述情况的任何其他建议或改进?

这是我为我的问题制定的解决方案。希望对其他人也有帮助。

awk '{=;print}' file.json | sed 's/: /:/' | tr -d '\n'

感谢 Whosebug 上的少数 answers/comment 帮助了我:-

https://unix.stackexchange.com/a/205854/404618