Parsing JSON with Python

Justin Dupree -

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("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!",

    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


Article is closed for comments.