From f6a8b7765c7b1857a44e2eee6b2fc857bfb42d04 Mon Sep 17 00:00:00 2001 From: Holger Just Date: Mon, 23 Sep 2013 16:30:29 +0200 Subject: [PATCH] Nicer errors if json couldn't be parsed --- bin/json | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bin/json b/bin/json index 254299f..b4a59a6 100755 --- a/bin/json +++ b/bin/json @@ -14,7 +14,12 @@ else data = STDIN.read end -json = JSON.parse(data) +begin + json = JSON.parse(data) +rescue JSON::ParserError => err + $stderr.puts err.message + exit 1 +end if ARGV.include?('--color') require 'ap' ap json