:py:mod:`cobra.io.json` ======================= .. py:module:: cobra.io.json .. autoapi-nested-parse:: Provide functions for I/O in JSON format. Module Contents --------------- Functions ~~~~~~~~~ .. autoapisummary:: cobra.io.json.to_json cobra.io.json.from_json cobra.io.json.save_json_model cobra.io.json.load_json_model Attributes ~~~~~~~~~~ .. autoapisummary:: cobra.io.json.JSON_SPEC .. py:data:: JSON_SPEC :value: '1' .. py:function:: to_json(model: cobra.Model, sort: bool = False, **kwargs: Any) -> str Return the model as a JSON string. :param model: The cobra model to represent. :type model: cobra.Model :param sort: Whether to sort the metabolites, reactions, and genes or maintain the order defined in the model (default False). :type sort: bool, optional :param \*\*kwargs: Keyword arguments passed on to `json.dumps`. :type \*\*kwargs: Any :returns: JSON string representation of the cobra model. :rtype: str .. seealso:: :obj:`save_json_model` Write directly to a file. :obj:`json.dumps` Base function. .. py:function:: from_json(document: str) -> cobra.Model Load a cobra model from a JSON string. :param document: The JSON string representation of a cobra model. :type document: str :returns: The cobra model as interpreted from the JSON string. :rtype: cobra.Model .. seealso:: :obj:`load_json_model` Load directly from a file. .. py:function:: save_json_model(model: cobra.Model, filename: Union[str, pathlib.Path, IO], sort: bool = False, pretty: bool = False, **kwargs: Any) -> None Write the cobra model to a file in JSON format. :param model: The cobra model to represent. :type model: cobra.Model :param filename: File path or descriptor that the JSON representation should be written to. :type filename: str or file-like :param sort: Whether to sort the metabolites, reactions, and genes or maintain the order defined in the model (default False). :type sort: bool, optional :param pretty: 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` (default False). :type pretty: bool, optional :param \*\*kwargs: Keyword arguments passed to `json.dump`. :type \*\*kwargs: Any .. seealso:: :obj:`to_json` Return a string representation. :obj:`json.dump` Base function. .. py:function:: load_json_model(filename: Union[str, pathlib.Path, IO]) -> cobra.Model Load a cobra model from a file in JSON format. :param filename: File path or descriptor that contains the JSON document describing the cobra model. :type filename: str or file-like :returns: The cobra model as represented in the JSON document. :rtype: cobra.Model .. seealso:: :obj:`from_json` Load from a JSON string.