Get Raw json string in Newtonsoft.Json Library

You don’t need to write any converters, just use the JRaw type as follows:

public class SomeData
{
    [JsonProperty("object")]
    public JRaw SomeObject { get; set;}
    [JsonProperty("dsct")]
    public JRaw SomeDesct { get; set; }
}

Then you can access the raw value by checking the .Value property:

var rawJsonDesct = (string)data.SomeDesct.Value;

If you want to retain the string signature, just serialize the JSON to a hidden property and have the string conversion in the accessor call instead.

Leave a Comment