Json.NET & C# – How to Deserialize an Object ?

Published on February 14, 2016 by abundantcode

Filed under Json.NET

Last modified February 13, 2016

Print this page

rate 1 star rate 2 star rate 3 star rate 4 star rate 5 star
Your rating: none, Average: 0 (0 votes)

This article have been viewed 1517 times

One of the ways to Deserialize an object to JSON string in C# in the Json.NET is using the DeSerializeObject method defined in the JsonConvert method.

How to Deserialize an Object in C# using Json.NET ?

Below is a sample code snippet demonstrating how you can deserialize an object from Json string to C# object using Json.NET. It takes the json string that contains the employee information and deserializes it to the Employee class.

using System;
using System.Collections.Generic;
using Newtonsoft.Json;

namespace ACConsoleCSharp
    class Program
        static void Main(string[] args)
            string jsonTxt = @"{'Name': 'Abundantcode',
  'IsPermanent': true,
 'Departments': [
    'Product Engineering'
            Employee emp = JsonConvert.DeserializeObject<Employee>(jsonTxt);

    public class Employee
        public string Name { get; set; }
        public bool IsPermanent { get; set; }
        // Employee can belong to multiple departments
        public List<string> Departments { get; set; }

The Deserialized object contains the following data.


If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment


You might be Interested in these Posts

How to use array Rank in C# ?

In C# , the Rank property of the array is is used to get the rank of the array. In simple terms , ra...

How to get the CommandLine of the Current Application in C# ?

You might need to get the information that contains the commandline which is used to execute the cur...

How to read a connection string from web.config file in ASP.NET ?

Assume that you have a connectionstring configured in the web.config file of your ASP.NET applicatio...