@evalcontextfilter
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)

@ evalcontextfilter 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 )
dumps a structure to json so that its safe to use in <script> tags .