def nested_to_record(ds, prefix="<STR_LIT>", sep="<STR_LIT:.>", level=<NUM_LIT:0>):
singleton = False<EOL>if isinstance(ds, dict):<EOL><INDENT>ds = [ds]<EOL>singleton = True<EOL><DEDENT>new_ds = []<EOL>for d in ds:<EOL><INDENT>new_d = copy.deepcopy(d)<EOL>for k, v in d.items():<EOL><INDENT>if not isinstance(k, str):<EOL><INDENT>k = str(k)<EOL><DEDENT>if level == <NUM_LIT:0>:<EOL><INDENT>newkey = k<EOL><DEDENT>else:<EOL><INDENT>newkey = prefix + sep + k<EOL><DEDENT>if not isinstance(v, dict):<EOL><INDENT>if level != <NUM_LIT:0>:  <EOL><INDENT>v = new_d.pop(k)<EOL>new_d[newkey] = v<EOL><DEDENT>continue<EOL><DEDENT>else:<EOL><INDENT>v = new_d.pop(k)<EOL>new_d.update(nested_to_record(v, newkey, sep, level + <NUM_LIT:1>))<EOL><DEDENT><DEDENT>new_ds.append(new_d)<EOL><DEDENT>if singleton:<EOL><INDENT>return new_ds[<NUM_LIT:0>]<EOL><DEDENT>return new_ds<EOL>
A simplified json_normalize.

Converts a nested dict into a flat dict ("record"), unlike json_normalize,
it does not attempt to extract a subset of the data.

Parameters
----------
ds : dict or list of dicts
prefix: the prefix, optional, default: ""
sep : string, default '.'
    Nested records will generate names separated by sep,
    e.g., for sep='.', { 'foo' : { 'bar' : 0 } } -> foo.bar

    .. versionadded:: 0.20.0

level: the number of levels in the jason string, optional, default: 0

Returns
-------
d - dict or list of dicts, matching `ds`

Examples
--------

IN[52]: nested_to_record(dict(flat1=1,dict1=dict(c=1,d=2),
                              nested=dict(e=dict(c=1,d=2),d=2)))
Out[52]:
{'dict1.c': 1,
 'dict1.d': 2,
 'flat1': 1,
 'nested.d': 2,
 'nested.e.c': 1,
 'nested.e.d': 2}