auser auser - 4 months ago 8
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


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'