code: def do_tojson(eval_ctx, value, indent=None):
      
      policies = eval_ctx.environment.policies
      dumper = policies['json.dumps_function']
      options = policies['json.dumps_kwargs']
      if indent is not None:
          options = dict(options)
          options['indent'] = indent
      return htmlsafe_json_dumps(value, dumper=dumper, **options)
docs: Dumps a structure to JSON so that it's safe to use in ``<script>``
      tags.  It accepts the same arguments and returns a JSON string.  Note that
      this is available in templates through the ``|tojson`` filter which will
      also mark the result as safe.  Due to how this function escapes certain
      characters this is safe even if used outside of ``<script>`` tags.
  
      The following characters are escaped in strings:
  
      -   ``<``
      -   ``>``
      -   ``&``
      -   ``'``
  
      This makes it safe to embed such strings in any place in HTML with the
      notable exception of double quoted attributes.  In that case single
      quote your attributes or HTML escape it in addition.
  
      The indent parameter can be used to enable pretty printing.  Set it to
      the number of spaces that the structures should be indented with.
  
      Note that this filter is for use in HTML contexts only.
  
      .. versionadded:: 2.9