import json


def canonical_json(o):
    """
    Dumps an object as canonical JSON string.

    Canonical JSON does not contain an space (except in strings) and
    have all the keys sorted.

    Args:
        o: The object to dump.

    Return:
        The canonical JSON string.
    """
    return json.dumps(o, sort_keys=True)