Using JSONs Special Properties of $ref and $id | Jaress Loo:

I had never seen this $ref and $id tags before, so I didnโ€™t know how to use them or what to make of it. It turns out that in order to condense the JSON object into a smaller object, it avoids rewriting an object twice if it doesnโ€™t have to. In order to accomplish this, the JSON.NET serializer will serialize these special JSON properties of $id and $ref. Every object being serialized will get an $id. If that same exact object is used again somewhere in the same JSON object, it will use a $ref property to tell you that the particular object youโ€™re looking at has already been serialized. It then gives you the $id to lookup as the value of the $ref property so that you know where to find the object being referred to.

Phew. Wondered what $id was for in Json.NET. You can blast that shorthand if you want.

And wow, does this speed up getting info from a database to json. Between the Entity Framework objects and Json.NET, about all you need a programmer for is constructing the LINQ where clause.

Labels: , ,