How can I easily return responses that have a mix of normal objects and literal JSON strings that should be emitted inline in the JSON stream, exactly as-is without interpretation or encoding?
public JsonResult Something() {
var literalJson = "{\"a\":1,\"b\":2}";
return Json(new {
result = "success",
responseTime = DateTimeOffset.Now(),
data = literalJson // only, don't JSON-encode this, emit it as-is
});
}
Creating a LiteralJson
class could work, with a custom Converter
for it. But I'm not sure that makes the most sense.
I know how to make a custom Converter
if that's a solid implementation. Are there any other ways to achieve the same goal?