Architectural Changes in JSON.NET 5

| by Jonathan Allen Follow 578 Followers on May 09, 2013. Estimated reading time: 1 minute |

Newtonsoft’s JSON.NET has received a pair of architectural updates to make it easier to use in projects that involve third party libraries. The two features are known as DefaultSettings and Extension Data.

In JSON.NET 5r5, developers are allowed to override the serialization/deserialization options using the JsonSerializerSettings class. This is normally passed to the JsonConvert methods each time it is called, or used to create a new JsonSerializer.

Libraries that want to opt-in to the new default scheme can use JsonSerializer.CreateDefault. This will use the defaults the application has defined via the JsonConvert.DefaultSettings method. Libraries that don’t want to this behavior can continue creating instances of JsonSerializer normally.

It should be noted that JsonConvert.DefaultSettings accepts a Func<JsonSerializerSettings> rather than an instance of JsonSerializerSettings. This means a new copy of the default JsonSerializerSettings will be created each time it is needed.

The other change is support for extension data. This is data that is available in the raw JSON payload but isn’t otherwise represented in the class structure. Usually this occurs when the server definition changes but the client hasn’t been updated to match.

In WCF, extension data is made available via the IExtensibleDataObject interface. This offers a single property of type ExtensionDataObject, an opaque class that is nearly useless. Any data contained with the ExtensionDataObject is unavailable except to a data contract serializer. This means it only comes into play in those exceedingly rare cases where you serialize some data, deserialize it with an olded version of the code, reserialize, and then deserialize it with the original version again.

JSON.Net exposes its extension data as a dictionary of strings and JToken objects. This dictionary is exposed via a property or field tagged with the [JsonExtensionData] attribute. By using an attribute instead of an interface, developers are allowed to maintain encapsulation by marking the field as private.

Rate this Article

Adoption Stage

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

ServiceStack.Text by Chuck Wagner

ServiceStack.Text still seems to be the best performing option for handling JSON

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss

Login to InfoQ to interact with what matters most to you.

Recover your password...


Follow your favorite topics and editors

Quick overview of most important highlights in the industry and on the site.


More signal, less noise

Build your own feed by choosing topics you want to read about and editors you want to hear from.


Stay up-to-date

Set up your notifications and don't miss out on content that matters to you