# Buggy code
def __init__(self, timestamp, offset, attributes):
    """Initializes a text event object.

    Args:
      timestamp: The timestamp time value. The timestamp contains the
                 number of microseconds since Jan 1, 1970 00:00:00 UTC.
      offset: The offset of the attributes.
      attributes: A dict that contains the events attributes.
    """
    super(TextEvent, self).__init__(timestamp, eventdata.EventTimestamp.WRITTEN_TIME)

    self.offset = offset

    for name, value in iter(attributes.items()):
        # TODO: Revisit this constraints and see if we can implement
        # it using a more sane solution.
        if isinstance(value, py2to3.STRING_TYPES) and not value:
            continue
        setattr(self, name, value)


# Traceback (TypeError)
2016-07-21 12:52:47,488 [WARNING] (Worker_01 ) PID:8090 <worker_process> Unhandled exception while processing path spec: OS:/home/onager/code/plaso_onager/test_data/selinux.log.
2016-07-21 12:52:47,489 [ERROR] (Worker_01 ) PID:8090 <worker_process> ([u'UNKNOWN[', u'1323', u']'], {u'key': [(u'type', 0)], u'value': [(u'UNKNOWN[', 0)]}) is not JSON serializable
Traceback (most recent call last):
File "/home/onager/code/plaso_onager/plaso/multi_processing/worker_process.py", line 245, in _ProcessPathSpec
extraction_worker.ProcessPathSpec(parser_mediator, path_spec)
File "/home/onager/code/plaso_onager/plaso/engine/worker.py", line 679, in ProcessPathSpec
self._ProcessFileEntry(parser_mediator, file_entry)
File "/home/onager/code/plaso_onager/plaso/engine/worker.py", line 540, in _ProcessFileEntry
parser_mediator, file_entry, data_stream.name)
File "/home/onager/code/plaso_onager/plaso/engine/worker.py", line 629, in _ProcessFileEntryDataStream
parser_mediator, file_entry, data_stream_name)
File "/home/onager/code/plaso_onager/plaso/engine/extractors.py", line 248, in ParseDataStream
parser_mediator, parser, file_entry, file_object=file_object)
File "/home/onager/code/plaso_onager/plaso/engine/extractors.py", line 185, in _ParseFileEntryWithParser
parser.Parse(parser_mediator, file_object)
File "/home/onager/code/plaso_onager/plaso/parsers/interface.py", line 269, in Parse
self.ParseFileObject(parser_mediator, file_object, **kwargs)
File "/home/onager/code/plaso_onager/plaso/parsers/text_parser.py", line 477, in ParseFileObject
parser_mediator, use_key, parsed_structure)
File "/home/onager/code/plaso_onager/plaso/parsers/selinux.py", line 151, in ParseRecord
parser_mediator.ProduceEvent(event_object)
File "/home/onager/code/plaso_onager/plaso/parsers/mediator.py", line 488, in ProduceEvent
self._storage_writer.AddEvent(event_object)
File "/home/onager/code/plaso_onager/plaso/storage/zip_file.py", line 2903, in AddEvent
self._storage_file.AddEvent(event)
File "/home/onager/code/plaso_onager/plaso/storage/gzip_file.py", line 110, in AddEvent
self._WriteAttributeContainer(event)
File "/home/onager/code/plaso_onager/plaso/storage/gzip_file.py", line 84, in _WriteAttributeContainer
attribute_container)
File "/home/onager/code/plaso_onager/plaso/storage/interface.py", line 237, in _SerializeAttributeContainer
attribute_container)
File "/home/onager/code/plaso_onager/plaso/serializer/json_serializer.py", line 421, in WriteSerialized
return json.dumps(json_dict)
File "/usr/lib/python2.7/json/__init__.py", line 244, in dumps
return _default_encoder.encode(obj)
File "/usr/lib/python2.7/json/encoder.py", line 207, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python2.7/json/encoder.py", line 270, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python2.7/json/encoder.py", line 184, in default
raise TypeError(repr(o) + " is not JSON serializable")
TypeError: ([u'UNKNOWN[', u'1323', u']'], {u'key': [(u'type', 0)], u'value': [(u'UNKNOWN[', 0)]}) is not JSON serializable

# Fixed code
def __init__(self, timestamp, offset, attributes):
    """Initializes a text event.

    Args:
      timestamp (int): timestamp, which contains the number of microseconds
          since January 1, 1970, 00:00:00 UTC.
      offset (int): offset of the text event within the event source.
      attributes (dict[str,object]): event attributes.
    """
    super(TextEvent, self).__init__(timestamp, eventdata.EventTimestamp.WRITTEN_TIME)

    self.offset = offset

    for name, value in iter(attributes.items()):
        # TODO: Revisit this constraints and see if we can implement
        # it using a more sane solution.
        if isinstance(value, py2to3.STRING_TYPES) and not value:
            continue
        setattr(self, name, value)