JSONのフォーマットを読みやすくする
たとえば、
{"name":"fabpot/silex-skeleton","description":"Apre-configuredskeletonfortheSilexmicroframework","license":"MIT","type":"project","require":{"php":">=5.3.3","silex/silex":"~1.0","silex/web-profiler":"~1.0","symfony/browser-kit":"~2.3","symfony/class-loader":"~2.3","symfony/config":"~2.3","symfony/console":"~2.3","symfony/css-selector":"~2.3","symfony/debug":"~2.3","symfony/finder":"~2.3","symfony/form":"~2.3","symfony/monolog-bridge":"~2.3","symfony/process":"~2.3","symfony/security":"~2.3","symfony/translation":"~2.3","symfony/twig-bridge":"~2.3","symfony/validator":"~2.3"},"autoload":{"psr-0":{"":"src/"}},"extra":{"branch-alias":{"dev-master":"1.1.x-dev"}}}
みたいなjsonを読みたいときに
{ "name": "fabpot\/silex-skeleton", "description": "Apre-configuredskeletonfortheSilexmicroframework", "license": "MIT", "type": "project", "require": { "php": ">=5.3.3", "silex\/silex": "~1.0", "silex\/web-profiler": "~1.0", "symfony\/browser-kit": "~2.3", "symfony\/class-loader": "~2.3", "symfony\/config": "~2.3", "symfony\/console": "~2.3", "symfony\/css-selector": "~2.3", "symfony\/debug": "~2.3", "symfony\/finder": "~2.3", "symfony\/form": "~2.3", "symfony\/monolog-bridge": "~2.3", "symfony\/process": "~2.3", "symfony\/security": "~2.3", "symfony\/translation": "~2.3", "symfony\/twig-bridge": "~2.3", "symfony\/validator": "~2.3" }, "autoload": { "psr-0": { "_empty_": "src\/" } }, "extra": { "branch-alias": { "dev-master": "1.1.x-dev" } } }
というように変換して読みたいとき
by php
$ cat /tmp/hoge.json | php -r 'echo json_encode(json_decode(file_get_contents("php://stdin")), JSON_PRETTY_PRINT);'
by python
$ cat /tmp/hoge.json | python -mjson.tool
参照: http://stackoverflow.com/questions/352098/how-can-i-pretty-print-json-from-the-command-line?page=1
pythonいいわー