Permalink
Browse files

Merge pull request #90 from 4z3/131837926a2b938a3d61846e24a7853668d87f64

package json-print: fail if property cannot be found
  • Loading branch information...
2 parents fc9be59 + 1318379 commit d1764e5d7a1ce14c1e86b6a1a4de7427f480407b tv committed May 23, 2012
Showing with 12 additions and 4 deletions.
  1. +12 −4 package/bin/json-print
View
@@ -1,7 +1,15 @@
#! /usr/bin/env node
-value = JSON.parse(require('fs').readFileSync(process.argv[2]))
+filename = process.argv[2]
+jsonpath = []
+value = JSON.parse(require('fs').readFileSync(filename))
process.argv.slice(3).forEach(function (key) {
- value = value[key];
-});
-console.log(JSON.stringify(value, null, 2));
+ value = value[key]
+ jsonpath.push(key)
+ if (typeof value === 'undefined') {
+ console.error(filename + ':', jsonpath.join('.'), 'is', value)
+ process.exit(23)
+ }
+})
+
+console.log(JSON.stringify(value, null, 2))

0 comments on commit d1764e5

Please sign in to comment.