1 | |
---|
2 | __all__ = [ "to_json_string", "from_json_string", "json_fix"] |
---|
3 | |
---|
4 | import pkg_resources |
---|
5 | pkg_resources.require( "simplejson" ) |
---|
6 | |
---|
7 | import simplejson |
---|
8 | |
---|
9 | to_json_string = simplejson.dumps |
---|
10 | from_json_string = simplejson.loads |
---|
11 | |
---|
12 | def json_fix( val ): |
---|
13 | if isinstance( val, list ): |
---|
14 | return [ json_fix( v ) for v in val ] |
---|
15 | elif isinstance( val, dict ): |
---|
16 | return dict( [ ( json_fix( k ), json_fix( v ) ) for ( k, v ) in val.iteritems() ] ) |
---|
17 | elif isinstance( val, unicode ): |
---|
18 | return val.encode( "utf8" ) |
---|
19 | else: |
---|
20 | return val |
---|