3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

JSON文字列をシェル上で整形する方法

Last updated at Posted at 2015-03-03

Python2.6以上の環境であれば下記のコマンドで整形してくれます。

$ echo '{"hoge": 1, "fuga": ["a", "b", "c"], "piyo": {"a": ["d", "e", "f"]}}' | python -mjson.tool
{
    "fuga": [
        "a",
        "b",
        "c"
    ],
    "hoge": 1,
    "piyo": {
        "a": [
            "d",
            "e",
            "f"
        ]
    }
}

パースエラーも発見できます。

$ echo '{
    "hoge": "a"
    "fuga": "b"
}' | python -mjson.tool
Expecting , delimiter: line 3 column 5 (char 22)

参考:
http://docs.python.jp/2.6/library/json.html

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?