Permalink
Browse files

Merge branch 'master' of git://github.com/mclarkson/JSON.sh

  • Loading branch information...
2 parents 83f57c6 + a3053b1 commit 074475519d05cdd476a14947a082fc5f8469a543 @dominictarr committed Feb 18, 2013
Showing with 15 additions and 3 deletions.
  1. +8 −3 JSON.sh
  2. +7 −0 README.md
View
11 JSON.sh
@@ -4,6 +4,8 @@ throw () {
exit 1
}
+BRIEF=0
+
tokenize () {
local ESCAPE='(\\[^u[:cntrl:]]|\\u[0-9a-fA-F]{4})'
local CHAR='[^[:cntrl:]"\\]'
@@ -37,7 +39,7 @@ parse_array () {
done
;;
esac
- value=`printf '[%s]' "$ary"`
+ [[ $BRIEF -ne 1 ]] && value=`printf '[%s]' "$ary"`
}
parse_object () {
@@ -71,7 +73,7 @@ parse_object () {
done
;;
esac
- value=`printf '{%s}' "$obj"`
+ [[ $BRIEF -ne 1 ]] && value=`printf '{%s}' "$obj"`
}
parse_value () {
@@ -83,7 +85,8 @@ parse_value () {
''|[^0-9]) throw "EXPECTED value GOT ${token:-EOF}" ;;
*) value=$token ;;
esac
- printf "[%s]\t%s\n" "$jpath" "$value"
+ [[ ! ($BRIEF -eq 1 && ( -z $jpath || $value == '""' ) ) ]] \
+ && printf "[%s]\t%s\n" "$jpath" "$value"
}
parse () {
@@ -96,6 +99,8 @@ parse () {
esac
}
+[[ -n $1 && $1 == "-b" ]] && BRIEF=1
+
if [ $0 = $BASH_SOURCE ];
then
tokenize | parse
View
7 README.md
@@ -27,6 +27,13 @@ curl registry.npmjs.org/express | ./JSON.sh | egrep '\["versions","[^"]*"\]'
... try it and see
```
+## Options
+
+-b
+> Brief output. Exclude empty fields and duplicate data. This
+> will improve performance for larger queries.
+
+
## Examples
If you have any examples with JSON.sh, streaming twitter, github, or whatever!

0 comments on commit 0744755

Please sign in to comment.