詩と創作・思索のひろば

ドキドキギュンギュンダイアリーです!!!

Fork me on GitHub

Parsing JSON input and inspecting in a REPL

When you are to inspect a JSON, if you are already familier with its format, using jq may be a solution. But if you don't know its structure well? A REPL-way would be handy.

Using Reply, in .replyrc:

; .replyrc
script_line5 = sub j { our $j ||= do { require JSON; local $/; JSON::decode_json(scalar <STDIN>) } }

[ReadLine]

Enabling ReadLine plugin is required.

With this configuration, you can feed JSON input to reply cli. j() returns that JSON parsed.

% curl -s https://api.github.com/users/motemen | reply
0> j->{blog}
$res[0] = 'http://motemen.github.io/'
1> keys j
$res[1] = [
  'gravatar_id',
  'subscriptions_url',
  'organizations_url',
  …
]

はてなで一緒に働きませんか?