:tocdepth: 3 :py:mod:`gws.lib.jsonx` ======================= .. py:module:: gws.lib.jsonx **Source code:** :source:`gws.lib.jsonx` Package Contents ---------------- .. py:exception:: Error Bases: :py:obj:`gws.Error` Generic GWS error. .. py:function:: from_path(path: str) Converts a json file to a python dictionary. :param path: Path to json file. :returns: A Python object. :raises ``Exception``: If the given json is incorrect. .. py:function:: from_string(s: str) Converts a json string to a python dictionary. :param s: Json string. :returns: A Python object. :raises ``Error``: If the given json is incorrect. .. py:function:: to_path(path: str, x, pretty: bool = False, ensure_ascii: bool = True, default=None) Converts a dictionary to a json file. :param path: Destination of the json file. :param x: The dict to convert. :param pretty: If true then the json key-value pairs get ordered and correct indentation is used. :param ensure_ascii: If true non ASCII characters will be escaped. Else those characters will not be escaped. :param default: A function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError. .. py:function:: to_pretty_string(x, ensure_ascii: bool = True, default=None) -> str Converts a dictionary to a pretty json string. :param x: The dict to convert. :param ensure_ascii: If true non ASCII characters will be escaped. Else those characters will not be escaped. :param default: A function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError. .. py:function:: to_string(x, pretty: bool = False, ensure_ascii: bool = True, default=None) -> str Converts a dictionary to a json string. :param x: The dict to convert. :param pretty: If true then the json key-value pairs get ordered and correct indentation is used. :param ensure_ascii: If true non ASCII characters will be escaped. Else those characters will not be escaped. :param default: A function that should return a serializable version of obj or raise TypeError. The default simply raises TypeError.