def htmlsafe_json_dumps(obj, dumper=None, **kwargs):
 if (dumper is None):
  dumper = json.dumps
 rv = dumper(obj, **kwargs).replace(u'<', u'\\u003c').replace(u'>', u'\\u003e').replace(u'&', u'\\u0026').replace(u"'", u'\\u0027')
 return rv

def htmlsafe_json_dumps ( obj , dumper = None , ** kwargs ) : if ( dumper is None ) : dumper = json . dumps rv = dumper ( obj , ** kwargs ) . replace ( u'<' , u'\\u003c' ) . replace ( u'>' , u'\\u003e' ) . replace ( u'&' , u'\\u0026' ) . replace ( u"'" , u'\\u0027' ) return rv
works exactly like :func:dumps but is safe for use in <script> tags .