import json


def to_json(obj, indent=4, encoding='utf-8'):
    """
    Return an encoded JSON string converted from obj.

    obj (list or dict): object to be converted and encoded
    indent (int): indentation for the JSON output
    encoding (str): encoding to be used
    """
    return json.dumps(obj, indent=indent).encode(encoding)