Json.NET Updates:merge, Dependency injection, F # and JSONPath support

Source: Internet
Author: User

Json.NET 6.0 received 4 releases this year, the latest last week. Over these releases, several new features has been added, including several F # specific features, support for JSONPath qu Erying, ability to integrate with Dependency injection frameworks, ability to Merge JSON objects and more.

Serializers shipped with the. NET framework, the Data contract JSON serializer and Thejavascriptserializer, leave Improvement both on features and performance front. Json.NET fills this gap and is already a popular open-source alternative within the. NET community. It comes with several features such as Linq-to-json, BSON support, support foranonymous types, support for popular ORMs (E F and Nhiberate) and more, not present in the built-in counterparts. This, combined with better performance. (See the feature comparison and detailed benchmarks)

Some important features introduced this year then make Json.NET even better-

  • JSON merge-allows to Merge a JSON object or an array into another.

    This was similar to the JQuery's extend method, but was also recursive and gives more options in handling Arrays-when Merg ing arrays (including those nested within objects), you can specify whether they should be concatenated together, unioned, Merged by position, or completely replaced.

    Merge also works with Linq-to-json. There is a look in the tests to understand this feature better and the various use cases it supports.
  • Integration with Dependency Injection-you can now deserialize interfaces or abstract types directly if you specify a MEC Hanism to resolve such a type at runtime, such as using a dependency injection the framework like AUTOFAC or Ninject. All of the inherit from the Defaultcontractresolver, and use your own resolver in the serializer.
  • Several F # Specific features-support for discriminated unions, F # collections, F # lists, sequences, sets and maps. For new immutable collections, if collection of T have a constructor that takes ienumerable<t> then Json.NET would aut omatically work while deserializing to that collection.
  • Ability to handle metadata properties, without have to guarantee JSON object property order. Json.NET uses metadata for some features such as preserving types or references and requires the metadata to being ordered be Fore other properties for these features to work fine. A setting called Metadatapropertyhandling.readahead can set to enable the, at a slight cost of increased memory usage and lesser speed.
  • Full support for JSONPath querying. Similar to XPath, the useful for navigating JSON data and can being useful if you only need specific values without neces Sarily deserializing the entire JSON object.

Other interesting features is ability to deserialize nested DataTables as well as arrays within DataTables, support for S Ingle-line comments within JSON, support for Windows Phone 8.1 and more. Refer to posts from James newton-king for more details.

Another interesting and performant Third-party Alternative for serialization in. NET Isservicestack.text (now commercial O Pen source).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.