def ordered_json_str(ordered_dict):
    """Dump a dict to a minified JSON string with ordered keys."""
    kv_strs = []
    # Keys must be iterated over in alphabetical order in order to have
    # deterministic string dump functionality.
    for key, val in sorted(ordered_dict.items()):
        kv_strs.append(
            '"{k}":{q}{v}{q}'.format(
                k=key,
                v=val,
                # Numeric values don't have quotes around them. Note that this falls
                # apart for JSON objects or arrays, but these keyfile attributes
                # only map to strings and ints, so we can take this shortcut.
                q=("" if isinstance(val, int) else '"'),
            )
        )
    return "{" + ",".join(kv_strs) + "}"