title: TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type function is not JSON serializable
body: <p>Im trying to write a code that tracks the screen time usage. I came across this problem when trying to add something to a JSON file. I have no clue what it is as Im still relatively new to Python and all the other answers to similar questions on here have been so confusing that I dont understand and haven't yet found a definitive solution for my case</p>
  <p>A lot comes before this, but this is the relevant code:</p>
  <pre><code>        elif load_json == False:
              # JSON wont load if empty and if that is the case then this line will activate
              data[&quot;activities&quot;].append(self.process_json(data))
              added_to_existing = True
  
          if added_to_existing == False:
              # If this window is the first instance in Json file, it must create a new dict
              data[&quot;activities&quot;].append(self.process_json(data))
  
          first_time = False
          with open(&quot;Screentime/activities.json&quot;, &quot;w&quot;) as json_file:
              json.dump(data, json_file, indent=4, sort_keys=True)
          return data
  
      def process_json(self, data):
          current_window_data = {
              &quot;name&quot;: self.active_window,
              &quot;time_entry&quot;: [TimeEntries.specific_times],
          }
          return current_window_data
  
  class TimeEntries:
      def __init__(self, start_time_dt, end_time_dt):
          self.start_time_dt = start_time
          self.end_time_dt = end_time_dt
          self.start_time = self.start_time_dt.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)
          self.end_time = self.end_time_dt.strftime(&quot;%Y-%m-%d %H:%M:%S&quot;)
          self.days = 0
          self.hours = 0
          self.minutes = 0
          self.seconds = 0
  
      def specific_times(self):
          total_time = end_time - start_time
          print(total_time)
          self.days, self.seconds = total_time.days, total_time.seconds
          print(self.days)
          self.hours = self.days * 24 + self.seconds // 3600
          print(self.hours)
          self.minutes = (self.seconds % 3600) // 60
          print(self.minutes)
          self.seconds = self.seconds % 60
          print(self.seconds)
  
          return_list = {
              &quot;start_time&quot;: self.start_time,
              &quot;end_time&quot;: self.end_time,
              &quot;days&quot;: self.days,
              &quot;hours&quot;: self.hours,
              &quot;minutes&quot;: self.minutes,
              &quot;seconds&quot;: self.seconds,
          }
          return return_list
  </code></pre>
  <p>The error that this throws up is:</p>
  <pre><code>...
  File &quot;C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\json\encoder.py&quot;, line 431, in _iterencode
      yield from _iterencode_dict(o, _current_indent_level)
    File &quot;C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\json\encoder.py&quot;, line 405, in _iterencode_dict
      yield from chunks
    File &quot;C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\json\encoder.py&quot;, line 325, in _iterencode_list
      yield from chunks
    File &quot;C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\json\encoder.py&quot;, line 405, in _iterencode_dict
      yield from chunks
    File &quot;C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\json\encoder.py&quot;, line 438, in _iterencode
      o = _default(o)
    File &quot;C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1776.0_x64__qbz5n2kfra8p0\lib\json\encoder.py&quot;, line 179, in default
      raise TypeError(f'Object of type {o.__class__.__name__} '
  
  TypeError: Object of type function is not JSON serializable
  </code></pre>
  <p>If anybody could explain in simple english what is going on and how to fix this, please answer.</p>