Tuesday, February 12, 2013

Parsing json in bash

So maybe you're wandering around and a giant blob of json jumps up at you on the street!

 If you're on RHEL6 / CentOS6 you might have json_reformat handy from the yajl package ("yet another json library").

 But say, maybe you're on an older RHEL5 / CentOS5 box, what do you do?  Well it turns out you can probably run it through python to split it out into something grepable.

curl -s http://cbserver:8091/pools | python -mjson.tool



{
    "componentsVersion": {
        "ale": "8cffe61",
        "inets": "5.6",
        "kernel": "2.14.4",
        "mnesia": "4.4.19",
        "ns_server": "1.8.1-937-rel-enterprise",
        "os_mon": "2.2.6",
        "sasl": "2.1.9.4",
        "stdlib": "1.17.4"
    },
    "implementationVersion": "1.8.1-937-rel-enterprise",
    "isAdminCreds": false,
    "pools": [
        {
            "name": "default",
            "streamingUri": "/poolsStreaming/default",
            "uri": "/pools/default"
        }
    ],
    "uuid": "43f16796-d591-409b-a831-889eeac86984"
}


No comments:

Post a Comment