title: json.dump throwing "TypeError: {...} is not JSON serializable" on seemingly valid object?
body: <p><strong>Background</strong>: I am writing a python program which should manage my music files. It crawls directories and puts the files and their meta data (via mutagen), encoded in JSON, in a file as a simple "database". I have the directory searching fine, but when I try and save the database, or encode to JSON, it throws a "TypeError: {...} is not JSON serializable"
  (the ... are some keys and values from a dict, more on that below)</p>
  
  <p><strong>The Problem</strong>: The program builds a large dictionary object following this format:</p>
  
  <pre><code>{
      "&lt;song id&gt;":{
          "artist":"&lt;song artist&gt;",
          "album":"&lt;song album&gt;",
          "title":"&lt;song title&gt;"},
      ...
  }
  </code></pre>
  
  <p>Every single song file is indexed via this format. When I try to dump the database to a file, I get this:</p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;pyshell#2&gt;", line 1, in &lt;module&gt;
      sit()
    File "D:\workbench\ideas\musicmanager\v0\spider.py", line 116, in sit
      json.dump(js.db,f,True)
    File "C:\Python27\lib\json\__init__.py", line 181, in dump
      for chunk in iterable:
    File "C:\Python27\lib\json\encoder.py", line 428, in _iterencode
      for chunk in _iterencode_dict(o, _current_indent_level):
    File "C:\Python27\lib\json\encoder.py", line 402, in _iterencode_dict
      for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 402, in _iterencode_dict
      for chunk in chunks:
    File "C:\Python27\lib\json\encoder.py", line 436, in _iterencode
      o = _default(o)
    File "C:\Python27\lib\json\encoder.py", line 178, in default
      raise TypeError(repr(o) + " is not JSON serializable")
  TypeError: {'album': [u"Rooney's Lost Album"], 'title': [u'The Kids
  After Sunset'], 'artist': [u'Rooney']} is not JSON serializable
  </code></pre>
  
  <p>With the key for that particular song entry being</p>
  
  <pre><code>Rooney|Rooney's Lost Album|The Kids After Sunset|The Kids After Sunset.itunes.mp3
  </code></pre>
  
  <p>(the format for the id is a little bulky, I might end up hashing that...)</p>
  
  <p>So I tried to</p>
  
  <pre><code>json.dumps({'album': [u"Rooney's Lost Album"], 'title': [u'The Kids
  After Sunset'], 'artist': [u'Rooney']})
  </code></pre>
  
  <p>which worked fine, as did</p>
  
  <pre><code>json.dumps({"Rooney|Rooney's Lost Album|The Kids After Sunset|The Kids
  After Sunset.itunes.mp3":""})
  </code></pre>
  
  <p>And then I tried this:</p>
  
  <pre><code>rooney = "Rooney|Rooney's Lost Album|The Kids After Sunset|The Kids
      After Sunset.itunes.mp3"
  json.dumps({rooney:js.db['songsbyid'][rooney]})
  </code></pre>
  
  <p>Which failed with the type error again.</p>
  
  <p>Why does that object fail with json.dump? I have plenty of other objects with keys containing pipes "|" and apostrophes "'"... At the moment, I have no way for anyone else to test this, should I post a pickled version of the database object?</p>
  
  <p><strong>Additional Notes</strong></p>
  
  <ul>
  <li><p>The resulting object below json.dumps is fine, so I am wondering if the issue has to do with the size of the database in any way?</p>
  
  <blockquote>
    <blockquote>
      <blockquote>
        <p>{rooney:js.db['songsbyid'][rooney]}
        {"Rooney|Rooney's Lost Album|The Kids After Sunset|The Kids
        After Sunset.itunes.mp3": {'album': [u"Rooney's Lost Album"],
        'title': [u'The Kids After Sunset'], 'artist': [u'Rooney']}}</p>
      </blockquote>
    </blockquote>
  </blockquote></li>
  <li><p>If I exclude the song by renaming the extension so the script ignores it, another arbitrary song causes the same error. I renamed&amp;excluded this new song, and ran into ANOTHER new song... I don't know how many there are.</p></li>
  <li><p>I changed my program to crawl the next furthest sub-directory containing the original problem song, and json.dump raised a TypeError on a completely different song...</p></li>
  </ul>