Json.NET defines a JConstructor
type.
This is confusing, because (to the best of my knowledge) constructors are not part of JSON. I double-checked the JSON spec and browsed json.org but couldn't find anything. There also doesn't seem to be much documentation about this type anywhere on the web.
Because Json.NET is so widely used (it is even cosigned by Microsoft) I assume there has to be some reasonable motivation for including this representation in the object model. The problem is, any attempt on my part to determine that motivation is nothing but speculation.
I tested out the type and its serialization, and the apparent behavior is to just wrap JavaScript code such as new constructorName(...)
, e.g.:
new JConstructor("ctorExample",
new JValue("value"),
new JObject(
new JProperty("prop1", new JValue(1)),
new JProperty("prop2", new JValue(2)))
)
.ToString()
outputs
new ctorExample(
"value",
{
"prop1": 1,
"prop2": 2
}
)
So, what is the JConstructor
type intended to represent and why does it exist?