All pastes #964865 Raw Edit

Miscellany

public text v1 · immutable
#964865 ·published 2008-03-31 16:49 UTC
rendered paste body
def simplejson(thing):
    if (type(thing) is list or type(thing) is tuple):
        return '[' + ', '.join([simplejson(x) for x in thing]) + ']'
    elif (type(thing) is dict):
        return '{' + ', '.join(["%s: %s" %(simplejson(str(x)), simplejson(y)) for x,y in thing.iteritems()]) + '}'
    elif (type(thing) is int):
        return str(thing)
    else:
        return '"' + str(thing).replace("\"", "\\\"").replace("\n","\\n") + '"'