auser auser - 1 year ago 160
JSON Question

Parsing JSON with UNIX tools

I'm trying to parse JSON returned from a curl request, like so:

curl '' |
sed -e 's/[{}]/''/g' |
awk -v k="text" '{n=split($0,a,","); for (i=1; i<=n; i++) print a[i]}'

The above splits the JSON into fields, for example:

% ...
"text":"My status"
% ...

How do I print a specific field (denoted by the
-v k=text

Answer Source

I've never used it, but you could try out jsawk. It would be something like this (haven't tested this, so I may be wrong):

curl '' | jsawk -a 'return'
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download