def dump(data, file=sys.stdout, use_yaml=None, **kwds):
if use_yaml is None:<EOL><INDENT>use_yaml = ALWAYS_DUMP_YAML<EOL><DEDENT>def dump(fp):<EOL><INDENT>if use_yaml:<EOL><INDENT>yaml.safe_dump(data, stream=fp, **kwds)<EOL><DEDENT>else:<EOL><INDENT>json.dump(data, fp, indent=<NUM_LIT:4>, sort_keys=True, **kwds)<EOL><DEDENT><DEDENT>if not isinstance(file, str):<EOL><INDENT>return dump(file)<EOL><DEDENT>if os.path.isabs(file):<EOL><INDENT>parent = os.path.dirname(file)<EOL>if not os.path.exists(parent):<EOL><INDENT>os.makedirs(parent, exist_ok=True)<EOL><DEDENT><DEDENT>with open(file, '<STR_LIT:w>') as fp:<EOL><INDENT>return dump(fp)<EOL><DEDENT>
Dumps data as nicely formatted JSON string to a file or file handle

:param dict data: a dictionary to dump
:param file: a filename or file handle to write to
:param kwds: keywords to pass to json.dump