Created
August 25, 2011 22:27
-
-
Save jsjohnst/1172177 to your computer and use it in GitHub Desktop.
Terrible, but working JSON parser for flat JSON in already validated semantic form.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prints out each key/value pair: | |
awk '{ gsub(/[{}]/, "", $0); n=split($0,a,","); for (i=1; i<=n; i++) if(length(k) > 0) { if(index(a[i], k) != 0) { split(a[i],b,":"); print b[2]; } } else { print a[i] } }' | |
Example input: | |
{"verified":false,"protected":false,"location":"San Francisco"} | |
Example output: | |
"verified":false | |
"protected":false | |
"location":"San Francisco" | |
Here's how you specify which key you want from the JSON tree: | |
awk -v k=verified '{ gsub(/[{}]/, "", $0); n=split($0,a,","); for (i=1; i<=n; i++) if(length(k) > 0) { if(index(a[i], k) != 0) { split(a[i],b,":"); print b[2]; } } else { print a[i] } }' | |
Example input: | |
{"verified":false,"protected":false,"location":"San Francisco"} | |
Example output: | |
false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment