|
|
|
|
|
by keenerd
5160 days ago
|
|
I would not say better - different certainly. Jsonpipe is a lot slower and heavier. (Matters when you are adding json based web 2.0 integration to your router. For small cases jshon is 15x faster and uses 1/14th the ram.) And I would really want to avoid using jsonpipe inside of a loop. It also seems to handle typical use cases inelegantly. Probably the most common thing I use Jshon for is turning json into a tab deliminated text file. To compare both, here is a query that returns json search results: curl -s "https://aur.archlinux.org/rpc.php?type=search&arg=python"
If I want to get the name, version, votes and description into a single tab deliminated output with jshon: jshon -e results -a -e Name -u -p -e Version -u -p -e NumVotes -u -p -e Description -u | \
sed 's/^$/-/' | paste -s -d "\t\t\t\n"
With jsonpipe it looks like: jsonpipe | grep -e '^results/[0-9]*/(Name|Version|NumVotes|Description)\t' > matches.tmp
grep 'Name\t' matches.tmp | cut -f 2 > name.tmp
grep 'Version\t' matches.tmp | cut -f 2 > version.tmp
grep 'NumVotes\t' matches.tmp | cut -f 2 > vote.tmp
grep 'Description\t' matches.tmp | cut -f 2 > desc.tmp
sed -i 's/^$/-/' *.tmp
paste -d '\t\t\t\n' name.tmp version.tmp vote.tmp desc.tmp
rm {name,version,vote,desc}.tmp
Most of that awkwardness is from `paste` really wanting real files to operate on. But if you are going to use jsonpipe, you might as well just write the whole thing in Python.The one thing that I do like about jsonpipe is that each line has the fully self contained path. So you can shuffle (or otherwise destroy) the output but still have something with usable context. Except for the example above, where the order matters a lot. For really simple cases jsonpipe's method is nice. I might just port it to C so that there can be a fair comparison. |
|