Args:

        root (dict) : Nested dictionary (e.g., JSON object).
        parents (list) : List of ancestor keys.

    Returns
    -------
    list
        List of ``(key, value)`` tuples, where ``key`` corresponds to the
        ancestor keys of the respective value joined by ``'.'``.  For example,
        for the item in the dictionary ``{'a': {'b': {'c': 'foo'}}}``, the
        joined key would be ``'a.b.c'``.

    See also :func:`expand_items`.

def flatten_dict(root, parents=None, sep='.'):
    '''
    Args:

        root (dict) : Nested dictionary (e.g., JSON object).
        parents (list) : List of ancestor keys.

    Returns
    -------
    list
        List of ``(key, value)`` tuples, where ``key`` corresponds to the
        ancestor keys of the respective value joined by ``'.'``.  For example,
        for the item in the dictionary ``{'a': {'b': {'c': 'foo'}}}``, the
        joined key would be ``'a.b.c'``.

    See also :func:`expand_items`.
    '''
    if parents is None:
        parents = []

    result = []
    for i, (k, v) in enumerate(root.iteritems()):
        parents_i = parents + [k]
        key_i = sep.join(parents_i)
        if isinstance(v, dict):
            value_i = flatten_dict(v, parents=parents_i, sep=sep)
            result.extend(value_i)
        else:
            value_i = v
            result.append((key_i, value_i))
    return result