Linux users, how do you format JSON when working with it on the console? JSON is often used in RESTful APIs, etc., and it is very convenient and you often see it, but if you use it without formatting, it will not be readable. So, I often use the jq command. However, this is not a Linux standard and may not be available in production. This time, I will introduce how to format JSON with only standard Linux functions.
Python is installed as standard on Linux, but *** JSON Module *** is one of the standard Python libraries. There is. Passing JSON data in a pipe makes it easy to format on the console.
$ echo '{"key1": "value1", "key2": {"key3": "value3"}}' | python -m json.tool
{
"key1": "value1",
"key2": {
"key3": "value3"
}
}
Let's JSON life!
Recommended Posts