Serialize an object to a JSON string appropriate for API calls. Args: obj: The object to serialize. pretty: True to pretty-print the object. for_cloud_api: Whether the encoding should be done for the Cloud API or the legacy API. Returns: A JSON string representing the inp
(obj, pretty: bool = False, for_cloud_api: bool = True)
| 303 | @_utils.accept_opt_prefix('opt_pretty') |
| 304 | # pylint: disable-next=g-bad-name |
| 305 | def toJSON(obj, pretty: bool = False, for_cloud_api: bool = True) -> Any: |
| 306 | """Serialize an object to a JSON string appropriate for API calls. |
| 307 | |
| 308 | Args: |
| 309 | obj: The object to serialize. |
| 310 | pretty: True to pretty-print the object. |
| 311 | for_cloud_api: Whether the encoding should be done for the Cloud API or the |
| 312 | legacy API. |
| 313 | |
| 314 | Returns: |
| 315 | A JSON string representing the input. |
| 316 | """ |
| 317 | serializer = Serializer(not pretty, for_cloud_api=for_cloud_api) |
| 318 | encoded = serializer._encode(obj) # pylint: disable=protected-access |
| 319 | return json.dumps(encoded, indent=2 if pretty else None) |
| 320 | |
| 321 | |
| 322 | # pylint: disable-next=g-bad-name |
no test coverage detected