mongoexport json format UTF-8 characters

So, you just did an export of your mongoDB database into a JSON formatted file called exported.json.  In part, you did this because you have this crazy idea of using the JSON with another application.  Then you see some strange stuff in the URL fields you exported.  Specifically, you see stuff like \u0026 in them.  These are actually UTF-8 codes for the % (percent) symbol.  If you want to work the exported data back around to the stored format, you’ll want to check out Python’s json library.  I’ve included a starting point below.

import json
f = open('exported.json')
for line in f:
    print json.loads(line),

No comments:

Post a Comment