def prepare_for_json_encoding(obj):
    """
    Convert an arbitrary object into just JSON data types (list, dict, unicode str, int, bool, null).
    """
    obj_type = type(obj)
    if obj_type == list or obj_type == tuple:
        return [prepare_for_json_encoding(item) for item in obj]
    if obj_type == dict:
        # alphabetizing keys lets us compare attributes for equality across runs
        return OrderedDict(
            (prepare_for_json_encoding(k),
             prepare_for_json_encoding(obj[k])) for k in sorted(obj.keys())
        )
    if obj_type == six.binary_type:
        return smart_unicode_decode(obj)
    if obj_type == bool or obj is None or obj_type == six.text_type or isinstance(obj, numbers.Number):
        return obj
    if obj_type == PSLiteral:
        # special case because pdfminer.six currently adds extra quotes to PSLiteral.__repr__
        return u"/%s" % obj.name
    return six.text_type(obj)
Convert an arbitrary object into just JSON data types (list, dict, unicode str, int, bool, null).