author Benjamin Smedberg <>
Thu, 21 Aug 2008 10:46:53 -0400
changeset 21 05453eb3a58a
parent 20 5d1300521b43
permissions -rw-r--r--
Attempt, probably abortive, to push the type hierarchy into python and deal with it there. This involves schlepping a lot of data across the border which really shouldn't be necessary.
"""InterJSON is a JSON serialization of connected (recursively, even) object

import simplejson

def load(fd):
    g = simplejson.load(fd)
    serdict = {}

    def getAtIndex(i):
        if i in serdict:
            return serdict[i]

        item = g[i]

        serdict[i] = item
        if isinstance(item, dict):
            iter = item.iterkeys()
            iter = xrange(0, len(item))

        for k in iter:
            if isinstance(item[k], dict):
                item[k] = getAtIndex(item[k][u'sharp'])

        return item

    return getAtIndex(0)

if __name__ == '__main__':
    import sys
    print repr(load(open(sys.argv[1])))