def read(strVal):
    return eval(strVal)

def write(obj):
    result = list()
    _write(result,obj)
    return "".join(result)

def _write(result,obj):
    if isinstance(obj,dict):
        n = len(obj)
        result.append("{")
        for k, v in obj.items():
            _write(result,k)
            result.append(":")
            _write(result,v)
            n = n - 1
            if n > 0:
                result.append(",")
        result.append("}")
    elif isinstance(obj,list) or isinstance(obj,tuple):
        n = len(obj)
        result.append("[")
        for item in obj:
            _write(result,item)
            n = n - 1
            if n > 0:
                result.append(",")
        result.append("]")
    elif isinstance(obj,str) or isinstance(obj,unicode):
        result.append('"')
        obj = obj.replace('\\', r'\\')
        obj = obj.replace('"', r'\"')
        obj = obj.replace('\b', r'\b')
        obj = obj.replace('\f', r'\f')
        obj = obj.replace('\n', r'\n')
        obj = obj.replace('\r', r'\r')
        obj = obj.replace('\t', r'\t')
        result.append(obj)
        result.append('"')
    elif isinstance(obj,int) or isinstance(obj,long):
        result.append(str(obj))
    elif isinstance(obj,float):
        result.append("%f" % obj)
    elif obj is True:
        result.append("True")
    elif obj is False:
        result._append("False")
    elif obj is None:
        result.append("None")
    else:
        raise Exception, "Cannot write in JSON: %s" % repr(obj)

