def save_json_model(model, filename, sort=False, pretty=False, **kwargs):
obj = model_to_dict(model, sort=sort)<EOL>obj[u"<STR_LIT:version>"] = JSON_SPEC<EOL>if pretty:<EOL><INDENT>dump_opts = {<EOL>"<STR_LIT>": <NUM_LIT:4>, "<STR_LIT>": ("<STR_LIT:U+002C>", "<STR_LIT>"), "<STR_LIT>": True,<EOL>"<STR_LIT>": False}<EOL><DEDENT>else:<EOL><INDENT>dump_opts = {<EOL>"<STR_LIT>": <NUM_LIT:0>, "<STR_LIT>": ("<STR_LIT:U+002C>", "<STR_LIT::>"), "<STR_LIT>": False,<EOL>"<STR_LIT>": False}<EOL><DEDENT>dump_opts.update(**kwargs)<EOL>if isinstance(filename, string_types):<EOL><INDENT>with open(filename, "<STR_LIT:w>") as file_handle:<EOL><INDENT>json.dump(obj, file_handle, **dump_opts)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>json.dump(obj, filename, **dump_opts)<EOL><DEDENT>
Write the cobra model to a file in JSON format.

``kwargs`` are passed on to ``json.dump``.

Parameters
----------
model : cobra.Model
    The cobra model to represent.
filename : str or file-like
    File path or descriptor that the JSON representation should be
    written to.
sort : bool, optional
    Whether to sort the metabolites, reactions, and genes or maintain the
    order defined in the model.
pretty : bool, optional
    Whether to format the JSON more compactly (default) or in a more
    verbose but easier to read fashion. Can be partially overwritten by the
    ``kwargs``.

See Also
--------
to_json : Return a string representation.
json.dump : Base function.