mixinafJson::JsLiteral

afJson::JsLiteral

@Js

A JavaScript literal that is written out verbatim by JsonWriter.

Use JsLiterals to embed Javascript in your JSON objects. Note that the resultant string is no longer valid JSON, but can sometimes be a good get out of jail card.

jsonWriter.writeJson([
  "func" : JsLiteral("function() { ... }")
])

// --> { "func" : function() { ... } }

Your own classes may extend JsLiteral and their toStr() representation is output in the JSON.

Note that without JsLiteral, the function would be surrounded in quotes:

jsonWriter.writeJson([
  "func" : "function() { ... }"
])

// --> { "func" : "function() { ... }" }
fromStr

Source

static new fromStr(Str val)

Creates a JsonLiteral instance.