Your statements are true.
JConstructor
is designed to enable capture of dates in JavaScript Date format, e.g.: new Date(1234656000000)
. As noted in Serializing Dates in JSON:
Technically this is invalid JSON according to the spec, but all browsers and some JSON frameworks, including Json.NET, support it.
Thus JConstructor
will not appear when parsing JSON that conforms strictly to the current IETF proposed standard or the original JSON proposal.
JRaw
will never appear when parsing JSON using JToken.Parse(string)
. It is useful mainly to facilitate writing of pre-formatted JSON literals from a JToken
hierarchy. By using JRaw
, one can avoid parsing the already-formatted JSON simply in order to emit it, e.g.:
var root = new JObject(new JProperty("response", new JRaw(jsonLiteral)));
var rootJson = root.ToString();
can be done instead of the less-efficient:
var root = new JObject(new JProperty("response", JToken.Parse(jsonLiteral)));
It's also possible to deserialize to `JRaw` to capture a JSON hierarchy as a single string literal, though I don't see much use in doing so. For instance, given the class:
public class RootObject
{
public JRaw response { get; set; }
}
One can do:<p>
var rootDeserialized = JsonConvert.DeserializeObject<RootObject>(rootJson);
var jsonLiteralDeserialized = (string)rootDeserialized.response;
However, this is not necessarily more efficient than deserializing to a `JToken`.
- As you surmise, only
JArray
, JObject
, JProperty
and JValue
will appear when parsing strictly valid JSON.