Parsing JSON with Python

JustinDupree -

As our Jython implementation of Python does not contain the "json" library, a lot of our Python users have trouble figuring out how to get JSON working. Here's an example that should help:

    import org.json.JSONObject
    import org.json.JSONArray

    #How to create a brand new JSON object
    data = org.json.JSONObject()

    data.put("to","to")
    data.put("from", "from")
    data.put("network", "network")
    data.put("success", "success")
    data.put("duration", "duration")
    data.put("direction", "direction")
    data.put("date", "date")


    #How to parse a JSON object
    values = {
    "name":"Python works 2!",
    "voiceUrl":"http://website.com",
    "messagingUrl":"http://website2.com",
    "platform":"scripting",
    "partition":"staging"
    }

    myJson = org.json.JSONObject(values)

    say("the name inside of the values is " + myJson.get("name"))
    say("the platform inside of the values is " + myJson.get("platform"))
    say("the partition inside of the values is " + myJson.get("partition"))
Have more questions? Submit a request

0 Comments

Article is closed for comments.