jsonpython-2.7jboss-cli

reading json data from variable instead of file in python


I'm creating a python script to extract values from jboss-cli.sh which by default return output in below format:


    {
        "outcome" => "success",
        "result" => {
            "ActiveCount" => "0",
            "AvailableCount" => "0",
            "AverageBlockingTime" => "0",
            "AverageCreationTime" => "0",
            "CreatedCount" => "0",
            "DestroyedCount" => "0",
            "InUseCount" => "0",
            "MaxCreationTime" => "0",
            "MaxUsedCount" => "0",
            "MaxWaitCount" => "0",
            "MaxWaitTime" => "0",
            "TimedOut" => "0",
            "TotalBlockingTime" => "0",
            "TotalCreationTime" => "0",
            "statistics-enabled" => false
        }
    }

Now i'm converting this to JSON format using below code:

from jbossply.jbossparser import JbossParser parser = JbossParser() print(parser.parse(OUT))

so it is giving output as:

{u'outcome': u'success', u'result': {u'AverageBlockingTime': u'0', u'AvailableCount': u'0', u'statistics-enabled': False, u'MaxCreationTime': u'0', u'MaxUsedCount': u'0', u'CreatedCount': u'0', u'MaxWaitCount': u'0', u'TimedOut': u'0', u'InUseCount': u'0', u'ActiveCount': u'0', u'TotalBlockingTime': u'0', u'DestroyedCount': u'0', u'AverageCreationTime': u'0', u'TotalCreationTime': u'0', u'MaxWaitTime': u'0'}}

Now how to extract "AvailableCount" out of it. Tried json.load but not working.


Solution

  • Finally I got the answer by myself, parsed json to a variable and extracted result like beow:

    parser = JbossParser() data=(parser.parse(OUT)) TOTAL_CN=(data["result"]["AvailableCount"])