Serialize Raw JSON value

April 6, 2024 ยท View on GitHub

This sample uses Argon.JRaw properties to serialize JSON with raw content.

public class JavaScriptSettings
{
    public JRaw OnLoadFunction { get; set; }
    public JRaw OnUnloadFunction { get; set; }
}

snippet source | anchor

var settings = new JavaScriptSettings
{
    OnLoadFunction = new("OnLoad"),
    OnUnloadFunction = new("function(e) { alert(e); }")
};

var json = JsonConvert.SerializeObject(settings, Formatting.Indented);

Console.WriteLine(json);
// {
//   "OnLoadFunction": OnLoad,
//   "OnUnloadFunction": function(e) { alert(e); }
// }

snippet source | anchor