Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:19:47+00:00 2026-06-04T23:19:47+00:00

Background : I am writing a python program which should manage my music files.

  • 0

Background: 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)

The Problem: The program builds a large dictionary object following this format:

{
    "<song id>":{
        "artist":"<song artist>",
        "album":"<song album>",
        "title":"<song title>"},
    ...
}

Every single song file is indexed via this format. When I try to dump the database to a file, I get this:

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    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

With the key for that particular song entry being

Rooney|Rooney's Lost Album|The Kids After Sunset|The Kids After Sunset.itunes.mp3

(the format for the id is a little bulky, I might end up hashing that…)

So I tried to

json.dumps({'album': [u"Rooney's Lost Album"], 'title': [u'The Kids
After Sunset'], 'artist': [u'Rooney']})

which worked fine, as did

json.dumps({"Rooney|Rooney's Lost Album|The Kids After Sunset|The Kids
After Sunset.itunes.mp3":""})

And then I tried this:

rooney = "Rooney|Rooney's Lost Album|The Kids After Sunset|The Kids
    After Sunset.itunes.mp3"
json.dumps({rooney:js.db['songsbyid'][rooney]})

Which failed with the type error again.

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?

Additional Notes

  • 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?

    {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’]}}

  • If I exclude the song by renaming the extension so the script ignores it, another arbitrary song causes the same error. I renamed&excluded this new song, and ran into ANOTHER new song… I don’t know how many there are.

  • 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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:19:49+00:00Added an answer on June 4, 2026 at 11:19 pm

    Because it’s not actually a dictionary; it’s another mapping type that looks like a dictionary. Use type() to verify. Pass it to dict() to get a real dictionary from it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As a newbie to Python, and mainly having a background of writing scripts for
Background: I am writing a C++ program working with large amounts of geodata, and
Background I am writing a program that targets several different phones, including the iPhone.
I've been writing a background service which enforces my client's security policies on company
I'm using a pair of python programs, one of which should call the second.
Background I am writing a class library assembly in C# .NET 3.5 which is
I am quite new to python programming (C/C++ background). I'm writing code where I
I have a C++/Obj-C background and I am just discovering Python (been writing it
Background I'm writing a web application and I have a stored procedure which inserts
Background I am writing an application which has two distinct functions. Load a GPX

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.