import json
from datetime import datetime


def to_camel_case(snake_str):
    components = snake_str.split('_')
    return components[0] + ''.join(x.title() for x in components[1:])


def convert_underscore_to_hyphen(snake_str):
    return snake_str.replace("_", "-")


def convert_properties_to_camel_case(obj):
    if isinstance(obj, list):
        ret = []
        for o in obj:
            ret.append(convert_properties_to_camel_case(o))
        return ret
    else:
        d = obj.__dict__
        ret = {}
        for name in d:
            ret[to_camel_case(name)] = d[name]
        return ret


def convert_to_json(obj):
    def mapper(o):
        if isinstance(o, datetime):
            return o.isoformat()
        if hasattr(o, "__dict__"):
            return convert_properties_to_camel_case(o)
        else:
            return str(o)

    if hasattr(obj, "__dict__"):
        obj = convert_properties_to_camel_case(obj)

    return json.dumps(obj, default=mapper)
