You can use the C# dynamic type to make things easier. This technique also makes re-factoring simpler as it does not rely on magic-strings.

JSON

The JSON string below is a simple response from an HTTP API call, and it defines two properties: Id and Name.

{"Id": 1, "Name": "biofractal"}

C#

Use JsonConvert.DeserializeObject<dynamic>() to deserialize this string into a dynamic type then simply access its properties in the usual way.

dynamic results = JsonConvert.DeserializeObject<dynamic>(json);
var id = results.Id;
var name= results.Name;

If you specify the type of the results variable as dynamic, instead of using the var keyword, then the property values will correctly deserialize, e.g. Id to an int and not a JValue (thanks to GFoley83 for the comment below).

Note: The NuGet link for the Newtonsoft assembly is http://nuget.org/packages/newtonsoft.json.

Package: You can also add the package with nuget live installer, with your project opened just do browse package and then just install it install, unistall, update, it will just be added to your project under Dependencies/NuGet

Answer from biofractal on Stack Overflow
🌐
Newtonsoft
newtonsoft.com › json
Json.NET - Newtonsoft
Serialize and deserialize any .NET object with Json.NET's powerful JSON serializer. Create, parse, query and modify JSON using Json.NET's JObject, JArray and JValue objects.
🌐
NuGet
nuget.org › packages › newtonsoft.json
NuGet Gallery | Newtonsoft.Json 13.0.4
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package. #addin nuget:?package=Newtonsoft.Json&version=13.0.4
🌐
Newtonsoft
newtonsoft.com › json › help › html › serializingjson.htm
Serializing and Deserializing JSON
SerializeObject and DeserializeObject both have overloads that take a JsonSerializerSettings object. JsonSerializerSettings lets you use many of the JsonSerializer settings listed below while still using the simple serialization methods. ... For more control over how an object is serialized, ...
🌐
Medium
medium.com › @ieplt › comprehensive-guide-to-using-json-and-newtonsoft-json-in-net-ac67b7963e35
Comprehensive Guide to Using JSON and Newtonsoft.Json in .NET | by İbrahim Emre POLAT | Medium
June 14, 2024 - The mobile app can then parse this JSON array to display the products in a list view. Serialization is the process of converting an object into a format that can be easily stored or transmitted. Newtonsoft.Json makes it simple to serialize .NET objects into JSON strings.
Top answer
1 of 12
296

You can use the C# dynamic type to make things easier. This technique also makes re-factoring simpler as it does not rely on magic-strings.

JSON

The JSON string below is a simple response from an HTTP API call, and it defines two properties: Id and Name.

{"Id": 1, "Name": "biofractal"}

C#

Use JsonConvert.DeserializeObject<dynamic>() to deserialize this string into a dynamic type then simply access its properties in the usual way.

dynamic results = JsonConvert.DeserializeObject<dynamic>(json);
var id = results.Id;
var name= results.Name;

If you specify the type of the results variable as dynamic, instead of using the var keyword, then the property values will correctly deserialize, e.g. Id to an int and not a JValue (thanks to GFoley83 for the comment below).

Note: The NuGet link for the Newtonsoft assembly is http://nuget.org/packages/newtonsoft.json.

Package: You can also add the package with nuget live installer, with your project opened just do browse package and then just install it install, unistall, update, it will just be added to your project under Dependencies/NuGet

2 of 12
278

If you just need to get a few items from the JSON object, I would use Json.NET's LINQ to JSON JObject class. For example:

JToken token = JObject.Parse(stringFullOfJson);

int page = (int)token.SelectToken("page");
int totalPages = (int)token.SelectToken("total_pages");

I like this approach because you don't need to fully deserialize the JSON object. This comes in handy with APIs that can sometimes surprise you with missing object properties, like Twitter.

Documentation: Serializing and Deserializing JSON with Json.NET and LINQ to JSON with Json.NET

🌐
GitHub
github.com › JamesNK › Newtonsoft.Json
GitHub - JamesNK/Newtonsoft.Json: Json.NET is a popular high-performance JSON framework for .NET · GitHub
Json.NET is a popular high-performance JSON framework for .NET - JamesNK/Newtonsoft.Json
Starred by 11.3K users
Forked by 3.3K users
Languages   C#
🌐
C# Corner
c-sharpcorner.com › article › newtonsoft-json-deserialize-c-sharp-example
Newtonsoft JSON Deserialize in C# with Example
August 17, 2023 - Step 6. Create a new class, “module post,” for requesting json parse from the rest api client. Write the following program listing. using System; using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json.Linq; using System.Net; using System.IO; namespace newtonsoft_json { public class modulePost { public static string urlServer = "http://localhost/json/ws.php"; public void setURL(string url) { urlServer = url; } public string getURL() { return urlServer; } public string Post(string data) { string DataFromPHP = null; try { string url = getURL(); byte[] bu
Find elsewhere
🌐
C# Corner
c-sharpcorner.com › article › newtonsoft-json-vs-system-text-json-comparative-analysis
Newtonsoft.Json vs. System.Text.Json: Comparative Analysis
April 17, 2024 - Newtonsoft.Json, developed by James Newton-King, has been the go-to library for JSON serialization and deserialization in the .NET ecosystem for many years. It offers a wide range of features and has garnered widespread adoption among developers.
🌐
Newtonsoft
newtonsoft.com › json › help › html › Samples.htm
Samples
Over 100 code samples covering Json.NET's most commonly used functionality. ... Serializing JSON - Serializing and deserializing JSON, serializer settings and serialization attributes · LINQ to JSON - Parsing, querying, modifying and writing JSON · JSON Schema - Loading schemas and validating JSON. Note that JSON Schema validation has been moved to its own package. See https://www.newtonsoft.com/jsonschema for more details.
🌐
Ibex
ibex.tech › visualcpp › json › newtonsoft-json-library
Newtonsoft Json Library – Visual C++/CLI Development - IBEX
using namespace Newtonsoft::Json //----- CLASSES FOR THE JSON DESERIALIZATION ----- public ref class Json_global_channels { public: int channel_id; public: String ^channel_name; }; public ref class Json_user_results //For each sub group of json data create a new class and include it in the parent class { public: String ^valid_request; public: String ^password_key; }; public ref class JsonRootObject { public: Json_user_results ^user_results; //Name the object to match the name in json, in this case "user_results" public: array<Json_global_channels^> ^global_channels; //Use an array (or List) for repeating json data };
🌐
Dynamics Community
community.dynamics.com › blogs › post
Serialization/Deserialization of JSON objects using ...
February 22, 2023 - We use foreach to cycle through each individual lead. Accessing the lead data is as easy as accessing the objects. We simply use lead.[Field Name] to get the required data. Thank you for reading our blog. The post Serialization/Deserialization of JSON objects using Newtonsoft.Json in C# appeared first on Nebulaa IT Solutions.
🌐
IronPDF
ironpdf.com › ironpdf blog › .net help › newtonsoft jsonpath
Newtonsoft Jsonpath (How It Works For Developers) | IronPDF
July 29, 2025 - In this code, the metadata object contains properties like Author, Title, CreateDate, etc. These are serialized into a JSON string and written to a file named "metadata.json." Combining Newtonsoft.Json and IronPDF allows you to convert data between PDF files and JSON, fulfilling a wide range of use cases.
🌐
C# Corner
c-sharpcorner.com › blogs › newtonsoftjsonjsonconvert-c-sharp
Newtonsoft.Json.JsonConvert In C#
May 15, 2023 - Create the Json Format to send requests and get a response. using Newtonsoft.Json; public class Response { MyJson myJson = new MyJson(); myJson.customer_id = "C1"; myJson.customer_name="Mathew" string json1 = JsonConvert.SerializeObject(myJson); var data1 = new StringContent(json1, Encoding.UTF8, "application/json"); var url = "Your Request ApiUrl"; var client = new HttpClient(); var response = client.PostAsync(url, data1); dynamic result = response.Result.Content.ReadAsStringAsync().Result; var jObject = JsonConvert.DeserializeObject(result); foreach (var obj in jObject.searchResults.results) { // Your logic.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › standard › serialization › system-text-json › migrate-from-newtonsoft
Migrate from Newtonsoft.Json to System.Text.Json - .NET | Microsoft Learn
Most of the workarounds presented here require that you write custom converters. You can write a custom converter in C# and register it in a Visual Basic project. For more information, see Visual Basic support. The following table lists Newtonsoft.Json features and System.Text.Json equivalents.
🌐
C# Corner
c-sharpcorner.com › article › net-core-tips-three-approaches-to-working-with-json-using-libraries-like-newto
Working with JSON in .NET Core: Newtonsoft.Json, NetJSON, and System.Text.Json
November 24, 2024 - In this article, we will learn three effective approaches to working with JSON in .NET Core using popular libraries: Newtonsoft.Json, NetJSON, and System.Text.Json.
🌐
Newtonsoft
newtonsoft.com › json › help › html › CreatingLINQtoJSON.htm
Creating JSON
Setting values and creating objects and arrays one at a time gives you total control, but it is more verbose than other options. ... JArray array = new JArray(); JValue text = new JValue("Manual text"); JValue date = new JValue(new DateTime(2000, 5, 23)); array.Add(text); array.Add(date); string json = array.ToString(); // [ // "Manual text", // "2000-05-23T00:00:00" // ]
🌐
Stack Overflow
stackoverflow.com › questions › 74852673 › how-to-deserialize-this-json-using-newtonsoft-json-c
how to deserialize this JSON using Newtonsoft.Json C#? - Stack Overflow
{ "catalog": { "book": [ { "id": "1", "author": "Autho1", "title": "GDB", "genre": "Kl", "price": "15", "publish_date": "1999-09-02", "description": "desc about book" }, { "id": "2", "author": "Lil", "title": "JS", "genre": "DS", "price": "3.6", "publish_date": "1999-09-02", "description": "desc 2." } ] } } I need to deserialize JSON into a structure, but in the end I have book = nil ... The frontpage of newtonsoft.com/json provides a great example to both serialize and deserialize.
🌐
Medium
medium.com › @mitra.sumit › extracting-specific-values-from-json-in-c-with-newtonsoft-json-a5d37ac21539
Extracting Specific Values from JSON in C# with Newtonsoft.Json | by Sumit Mitra | Medium
March 12, 2024 - In this example, the `JObject.Parse` ... or directly accessing values with `JObject`, Newtonsoft.Json provides a flexible and powerful way to work with JSON in C#....