class JSRaw(int): """Hack to allow including raw Javascript code in simplejson.dumps output. Objects of this sort are dumped as raw strings. """ def __new__(self, string): instance = int.__new__(self, 0) instance.string = string return instance def __repr__(self): return self.string def __unicode__(self): return self.string def __str__(self): return self.string
Example:
s = jsondumps({ 'series': data, 'yAxis': { 'labels': { 'formatter': JSRaw(""" function() { return (this.value > 0 ? '+' : '') + this.value + '%'; }""") } } })