MCPcopy
hub / github.com/danielgtaylor/python-betterproto / to_json

Method to_json

src/betterproto/__init__.py:1634–1669  ·  view source on GitHub ↗

A helper function to parse the message instance into its JSON representation. This is equivalent to:: json.dumps(message.to_dict(), indent=indent) Parameters ----------- indent: Optional[Union[:class:`int`, :class:`str`]] The indent

(
        self,
        indent: Union[None, int, str] = None,
        include_default_values: bool = False,
        casing: Casing = Casing.CAMEL,
    )

Source from the content-addressed store, hash-verified

1632 return self
1633
1634 def to_json(
1635 self,
1636 indent: Union[None, int, str] = None,
1637 include_default_values: bool = False,
1638 casing: Casing = Casing.CAMEL,
1639 ) -> str:
1640 """A helper function to parse the message instance into its JSON
1641 representation.
1642
1643 This is equivalent to::
1644
1645 json.dumps(message.to_dict(), indent=indent)
1646
1647 Parameters
1648 -----------
1649 indent: Optional[Union[:class:`int`, :class:`str`]]
1650 The indent to pass to :func:`json.dumps`.
1651
1652 include_default_values: :class:`bool`
1653 If ``True`` will include the default values of fields. Default is ``False``.
1654 E.g. an ``int32`` field will be included with a value of ``0`` if this is
1655 set to ``True``, otherwise this would be ignored.
1656
1657 casing: :class:`Casing`
1658 The casing to use for key values. Default is :attr:`Casing.CAMEL` for
1659 compatibility purposes.
1660
1661 Returns
1662 --------
1663 :class:`str`
1664 The JSON representation of the message.
1665 """
1666 return json.dumps(
1667 self.to_dict(include_default_values=include_default_values, casing=casing),
1668 indent=indent,
1669 )
1670
1671 def from_json(self: T, value: Union[str, bytes]) -> T:
1672 """A helper function to return the message instance from its JSON

Calls 1

to_dictMethod · 0.95