import json


def to_json(obj):
    """Create a compact JSON string from an object"""

    byte_dump = json.dumps(obj)
    if isinstance(byte_dump, bytes):
        return byte_dump
    return byte_dump.encode("utf8")