code: def htmlsafe_json_dumps(
      obj: t.Any,
      dumps: t.Optional[t.Callable[..., str]] = None,
      **kwargs: t.Any,
  ) -> markupsafe.Markup:
      """Serialize an object to a string of JSON with :func:`json.dumps`,
      then replace HTML-unsafe characters with Unicode escapes and mark
      the result safe with :class:`~markupsafe.Markup`.
  
      This is available in templates as the ``|tojson`` filter.
  
      The following characters are escaped: ``<``, ``>``, ``&``, ``'``.
  
      The returned string is safe to render in HTML documents and
      ``<script>`` tags. The exception is in HTML attributes that are
      double quoted; either use single quotes or the ``|forceescape``
      filter.
  
      :param obj: The object to serialize to JSON.
      :param dumps: The ``dumps`` function to use. Defaults to
          ``env.policies["json.dumps_function"]``, which defaults to
          :func:`json.dumps`.
      :param kwargs: Extra arguments to pass to ``dumps``. Merged onto
          ``env.policies["json.dumps_kwargs"]``.
  
      .. versionchanged:: 3.0
          The ``dumper`` parameter is renamed to ``dumps``.
  
      .. versionadded:: 2.9
      """
      if dumps is None:
          dumps = json.dumps
  
      return markupsafe.Markup(
          dumps(obj, **kwargs)
          .replace("<", "\\u003c")
          .replace(">", "\\u003e")
          .replace("&", "\\u0026")
          .replace("'", "\\u0027")
      )
  
imports: import enum
  import json
  import os
  import re
  import typing
  from collections import abc
  from collections import deque
  from random import choice
  from random import randrange
  from threading import Lock
  from types import CodeType
  from urllib.parse import quote_from_bytes
  import markupsafe
label_desc: Use image node_id 16 for calling a global function with example usage: htmlsafe_json_dumps(obj, dumps) and returns: markupsafe