import json


def get_json(data, pretty=False, **kwargs):
    """
    A convenience wrapper around ``json.dumps`` that respects the ordering of
    keys in classes like ``OrderedDict``, ``SortedDict``, and
    ``DefinedOrderDict``.

    :param data: the object to encode in JSON
    :param pretty:
        whether or not the output should be indented in human-friendly ways
    :type pretty: boolean
    :returns: a JSON-encoded string
    """

    kwargs['ensure_ascii'] = False
    kwargs['sort_keys'] = False

    if pretty:
        kwargs['indent'] = 2
        kwargs['separators'] = (',', ': ')

    return json.dumps(data, **kwargs)