Click here to Skip to main content
15,891,253 members
Everything / JSON.NET

JSON.NET

JSON.NET

Great Reads

by thangchung
Learn to organize clean architecture to modular patterns
by Graeme_Grant
Working with simple JSON objects and collections to Custom Converters and Transformations into .NET classes - System.Text.Json
by Michael Doleman
A simple DAL with an integrated, lightweight model for database seeding from a JSON source, using the code-first method in Entity Framework.
by Hamid Mosalla
Dynamically building JSON tree for use In JavaScript components using C#

Latest Articles

by Graeme_Grant
How to deserialize very large simple & complex JSON Streams (.NET 6.0 & 7.0)
by Graeme_Grant
Working with simple JSON objects and collections to Custom Converters and Transformations into .NET classes - System.Text.Json
by Graeme_Grant
Working with simple JSON objects and collections to Custom Converters and Transformations into .NET classes - NewtonSoft.Json
by Uladzislau Baryshchyk
Easy way to work with JSON file in C#/.NET

All Articles

Sort by Updated

JSON.NET 

17 Mar 2024 by Vivek Kumar
This preform is very helpful for programmers. The community is very helpful. I generally write programs in c# language, but I don't know php at advanced level. In a project I need to write some code in PHP. please help me... This example will...
17 Mar 2024 by Andre Oosthuizen
As I am all about PHP, I found this interesting to play around with, be forewarned though that there are WAY more to the below code than what is given, you have to insert certain security measures, you need to know how to start a session to grab...
16 Mar 2024 by OriginalGriff
As Maciej has said, this is not a code conversion service: we are not here to translate code for you. Even if we did, what you would end up with would not be "good code" in the target language – they are based on very different frameworks, and...
16 Mar 2024 by Maciej Los
We are not a "C# to PHP" translator. I'd suggest to read this: How to begin? | C# to PHP converter[^]
10 Mar 2024 by Pete O'Hanlon
You are trying to deserialize a single instance of the ValueAddedService and pass this into the API. That would be fine if you were working with a single instance, but you actually deserialize into a list, which you are sending to the API.
28 Aug 2023 by Randy Kroeger
What I have done in the past, where the serializer is returning null on Deserialize, is to test Serializing my object to see what the serializer is expecting. Once I see that result, I can fix my objects so they now Deserialize correctly.
23 Jan 2023 by OriginalGriff
Run your code through a JSON class converter and it'll produce the following structures: Public Class Bd Public Property pickupAccountId As String Public Property soldToAccountId As String Public Property pickupDateTime As DateTime ...
23 Jan 2023 by Maideen Abdul Kader
Hi. I have error while generation Json. Error is Value of type 'ValueAddedService' cannot be converted to System.Collections.Generic.List(Of ValueAddedService)' Also date and time is "messageDateTime ="\/Date(1674459281468)\/" is not date time...
12 Jan 2023 by kksingh.hrp
Step 1: dynamic response = JsonConvert.DeserializeObject(json); Step 2: JArray paramsArray = (JArray)JToken.FromObject(response); Step 3: foreach (JToken param in paramsArray) { CustomerRoot...
12 Jan 2023 by Jakobson 2022
Hello, currently I am working on WinForms application that has been communicating with API which is based on websocket as a transport protocol where each message is json encoded object. I want to loop through each array in params JArray, take...
30 Dec 2022 by Maideen Abdul Kader
Hi I have an issue in nested Json from MSSQL datatable. I am using normal Json (not nested ). It works fine. But nested, I could not do. WayBillNo is Final outcome. Pls Advice me thank you Maideen Here is my code What I have...
29 Nov 2022 by stybjs
I tried to add a dictionary after load a file (JSON). However, it won't load, and I added it to the list I wanted to, but it won't work this way. if (File.Exists(fileName)) { StreamReader sr = new StreamReader(fileName); ...
29 Nov 2022 by Graeme_Grant
Your first issue is that the JSON above is a single object, not a collection of objects. Json collections are surrounded in square brackets. So Your JSON should be: [{ "Name": "Lea", "Breed": "German", "Age": 17, "Vaccines": null }] When...
16 Nov 2022 by Graeme_Grant
How to deserialize very large simple & complex JSON Streams (.NET 6.0 & 7.0)
31 Oct 2022 by Graeme_Grant
Working with simple JSON objects and collections to Custom Converters and Transformations into .NET classes - System.Text.Json
31 Oct 2022 by Graeme_Grant
Working with simple JSON objects and collections to Custom Converters and Transformations into .NET classes - NewtonSoft.Json
28 Sep 2022 by kishore Rajendran
How can we parse the following json format. "metadata": { "name": "", "latitude": 51.18, "longitude": 3.81, "height": 9, "timezone_abbrevation": "CEST", "utc_timeoffset": 2.00, "modelrun_utc": "4716-04-07 12:00" }, ...
28 Sep 2022 by Graeme_Grant
Here are the classes for that JSON data: ����public�class�Metadata ����{ ��������[JsonProperty("name")] ��������public�string�Name�{�get;�set;�} ��������[JsonProperty("latitude")] ��������public�double�Latitude�{�get;�set;�} ...
2 Sep 2022 by Gcobani Mkontwana
I want to do the following logic on my WPF Desktop application that will; This is the TCP server program that echoes your sent data back to you. Start echotool as follows: echotool /p tcp /s 12345 It must first have two buttons one...
31 Jul 2022 by Member 15244870
I am reading 2 REST APIs using Httpclient in C#. The APIs return following employee data in JSON format: **1st API** { "status": "OK", "content": { "empid1": 89900, "empid2": 45550, ...
31 Jul 2022 by Member 12274589
Solution: 1 Make sure your both API returns as below [{ "status": "OK", "content": { "empid1": 89900, "empid2": 45550, "empid3": 22350} }] Solution : 2 Update your wrapper class property...
4 Jul 2022 by Richard MacCutchan
The paramsArray variable is an array of arrays, not an array of JSON objects. So you probably need something like: JArray paramsArray = (JArray)jObject["params"]; List listName = new List(); foreach(JToken param in paramsArray)...
4 Jul 2022 by Jakobson 2022
I've found out how can be done after spending a while, through the while loop I hardcoded the last index number of child arrays, and then do the iteration over all, maybe there exists different solution for this, but for now this logic for me...
4 Jul 2022 by Graeme_Grant
Here is how to pull the doneyears: //List listName = new List(); Dictionary> map = new Dictionary>(); foreach(JToken param in paramsArray) { string name =...
5 May 2022 by Palle Hansen
public string GetJsonPropertyFieldName(PropertyInfo t) { var attr = t.GetCustomAttributes(typeof(JsonPropertyAttribute), true).FirstOrDefault() as JsonPropertyAttribute; return attr?.PropertyName; } IList entityprops = new...
5 May 2022 by elfenliedtopfan5
Good Morning/Afternoon, i have a json file that is parsed I currently am using lineq to access the data in the json file but would like to create a list of all objects and be able to loop through all the data in there so i can find certain name...
10 Apr 2022 by Member 11573837
I want extrac noeud of a json and return json value c# for exapmle: i have this Json result : { "Features": { "FeatureActive": true, "FeatureRelanceAutoJSON": { "RelanceAuto": { ...
10 Apr 2022 by OriginalGriff
The simplest way is to feed your JSON example into a online JSON to C~ converter: Convert JSON to C# Classes Online - Json2CSharp Toolkit[^] is the one I use. That produces C# classes to match the data: // Root myDeserializedClass =...
14 Feb 2022 by Pinky Pinky
I have the following JSON. I want to fetch the rdfs:label's value when the type is @type": "owl:DbType and rdfs:class is given any class (GreenPlant/GreenPlantHistory) For example: If @type": "owl:DbType and the class is GreenPlant, fetch...
14 Feb 2022 by OriginalGriff
Start by defining classes that are compatible with the JSON data: Convert JSON to C# Classes Online - Json2CSharp Toolkit[^] will do that for you: public class RdfsClass { [JsonProperty("@id")] public string Id { get; set;...
6 Nov 2021 by DevJr
I'm new in Json, already searching many info but no luck, based on: json add new object to existing json file C# - Stack Overflow[^] (have tried it, and it's works) But that needs an array json format (begin with [ , ends with ]), mine is object...
6 Nov 2021 by DevJr
How to get max ID from json (Array) fromat below: [ { "Group": "1", "ID": 1, "Name": "User1", "Description": "Desc1" }, { "Group": "2", "ID": 3, "Name": "User2", "Description": "Desc2" }, { ...
6 Nov 2021 by DevJr
Hmmm... got it! this works for json that begin with [, i think for some tweaks, this will also works for the json that begin with { public int GetMaxIDLINQ() { var userLists = JsonConvert.DeserializeObject>(json); int...
5 Nov 2021 by DevJr
1. The json (Array) format: [ { "Group": "1", "ID": 1, "Name": "User1", "Description": "Desc1" }, { "Group": "2", "ID": 3, "Name": "DeleteMe", "Description": "Desc2" }, { "Group": "3", "ID": 2, ...
5 Nov 2021 by OriginalGriff
Create an object that contains the two instances as properties and serialize that to JSON. Seriously, you have three questions in thirty minutes here that show you have no idea what JSON is or what you should do with it - you appear to be...
5 Nov 2021 by OriginalGriff
The way you do it is not to manipulate the JSON directly: you read the JSON data into C~ objects - that's what Newtonsoft is there for - manipulate the C# objects, then cretae your summary data from that. Manipulating the JSON directly is a PITA...
5 Nov 2021 by OriginalGriff
The way you do it is not to manipulate the JSON directly: you read the JSON data into C~ objects - that's what Newtonsoft is there for - manipulate the C# objects, then create new JSON data from them. Manipulating the JSON directly is a PITA...
5 Nov 2021 by Richard MacCutchan
See NewtonSoft Introduction[^]
26 Oct 2021 by Muhammad Tufail Ali Younus
hello, my code is working only for one file, but i have multiple json files and i have to remove last comma from each json files. What I have tried: string filepath = "E:/prod/1.json"; string result = string.Empty; using...
26 Oct 2021 by phil.o
So you have some code which does the job for one file. You could: - take the part which is reponsible for processing one file, and make it a method. Give this method the path to the file to be processed as a parameter. - then enumerate the files...
6 Jul 2021 by Richard Deeming
Your class structure doesn't match your JSON. Public Class Root Public Property status As Boolean Public Property message As String Public Property data As List(Of BouncesAndBlocks) End Class Public Class BouncesAndBlocks Public...
6 Jul 2021 by Maideen Abdul Kader
Hi I have an issue in stored the Json Data into database Please advice me Thank you Maideen Error: Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type...
5 Jul 2021 by Richard MacCutchan
You are trying to convert a single name/value pair into a List: {"status":true,"message":"Success", You need to process that field first and use the text following the data key as the List.
5 Jul 2021 by Richard Deeming
Quote: [JsonProperty("data")] public List empdata { get; set; } = new List(); According to the samples in your question, neither API returns a property called data. They both have a property called content, but it is not a list;...
22 May 2021 by DSFVDSCSDC
I cannot import the json content in the example into the tables with the standard displayed codes. How do I convert nested data to datatable? What I have tried: public class Location { public double lat { get; set;...
22 May 2021 by Sandeep Mewara
You can use any online JSON to C# class converter for the same: // Usage // Root myDeserializedClass = JsonConvert.DeserializeObject(myJsonResponse); public class Location { public double lat { get; set; } public double lon {...
17 May 2021 by Manidas Payyoli
Hi i have a function which will check given project name is include in the json object. For that I am not getting a proper json object in my response how to do that? this is my object ...
17 May 2021 by raddevus
You didn't tell us what the actual error is: Is the for loop ever entered? Or, does it cause an error when the for loop is entered? I'm going to guess that the for loop is never entered. That means the JSONObj.length is probably 0. Most...
22 Apr 2021 by OriginalGriff
Quote: have tryied creating a new instance of track elfen = new track() elfen.name but it returns null, It will do - you are creating a new instance of the track class, and that means everything in the instance will be empty. Since you read the...
5 Apr 2021 by Maideen Abdul Kader
Hi Sir I need insert API - Json Data into mssql server. I did halfway through. I have no idea how to proceed.... Please advise me Maideen What I have tried: Public Class BouncesAndBlocks Public Property name As String ...
5 Apr 2021 by Maideen Abdul Kader
Hi This is the code inserting json data into mssql database Dim url As String = "http://localhost/delivery/JsonData/WebService.asmx/GetAllCustomer" ServicePointManager.Expect100Continue = True ...
14 Mar 2021 by Uladzislau Baryshchyk
Easy way to work with JSON file in C#/.NET
12 Feb 2021 by Aneets
Hi, Am really struggling with Posting Json to a Secure Rest API in a VB.net Compact 3.5 App. Below is the first Piece of code I tried and I get a error that 'Could not establish secure channel for SSL/TLS' Imports Newtonsoft.Json Imports System.Net Imports System.IO Imports System.Text Public...
12 Feb 2021 by Member 10478623
I am facing the same issue with my legacy vb.net 3.5 solution. Were you ever able to get a workaround for this issue, if so please share. Thanks,
5 Oct 2020 by Robert P. Howard
How to deserialize a JSON string that contains nested polymorphic objects
31 Aug 2020 by Member 14803832
I'm doing a service where I'm changing some data in DB via bootstrap modal dialog. After uploading file I'm showing name of this in my modal dialog body. But I can not see the name of the file what I've just uploadet, I have to close dialog and...
19 Aug 2020 by Member 14914599
My phone is 3 days old and is showing 19 gigs storage systems that I can't access or delete cannot factory reset phone and get rid of any options What I have tried: Factory reset it won't wipe data it will only go back to win things were...
19 Aug 2020 by Stefan_Lang
Unfortunately that is something all mobile vendors do nowadays: pack the phone full of apps no matter what, and make it hard to impossible to remove them. I've read the mobile vendors make deals with the app vendors to earn some extra cash...
18 Aug 2020 by OriginalGriff
This is not a technical support site for phones: start with the people you bought it from and / or the phone manufacturers.
11 Aug 2020 by Member 14803832
After uploading file more that 0,5MB into SQL database, my AJAX call falls into error: function(){if(a){var t=a.length;(function r(t){v.each(t,function(t,n){var...
6 Aug 2020 by Member 14803832
I'm trying to implement file download functionality thru ajax call in MVC. After calling of controller method i always have a "parseerror", can somebody explain me why? with simple download link in razor it works, but not with ajax. What am I...
6 Aug 2020 by Member 14803832
tab.on("click", ".FileDownload", function (e) { //$('#uploadStatus').html("ok"); var tr = $(this).closest("tr"); var id = tr.data("id"); window.location = window.location.origin + '/File/FileDownload?fileId=' + id; }); ...
4 Aug 2020 by Member 13668663
I am trying to create a JSON schema with the usage of Json.NET Schema. Anyway, my class has JsonConverter attribute, like in the example below: public class Building { [JsonConverter(typeof(BuildConverter))] public string Name { get; set; }...
29 Jul 2020 by Member 14902374
I am using a Dictionary to create Json file. The data in the Dictionary would look similar to this: Dictionary inputValues = new Dictionary(); inputValues.Add("Employee.Person.PersonalInfo.HRCode", "HR1234");...
29 Jul 2020 by BillWoodruff
I think you are creating a nightmare parsing scenario with this strategy. Why not use your strongly typed classes with the WCF JSON DataContractJsonSerializer: [^]
6 Jul 2020 by Member 14803832
I have a form where I'm adding some values in DB using AJAX and I've made all the logic to avoid adding if there is some duplicated value, but I want to show a simple message below id="txtTitle" input, that "such number already exists". Until now...
6 Jul 2020 by Richard Deeming
Change the shape of the data you're returning: [HttpPost] public JsonResult AddNewEvent(Event e) { try { using(EventsDBEntities db = new EventsDBEntities()) { if (db.Events.Any(x => x.Title == e.Title)) ...
19 May 2020 by OriginalGriff
If I pass your code to a Class creator (such as JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^]) I dont; get such a limited class, as I'd expect: Public Class Value Public Property cotacaoVenda As Double End...
19 May 2020 by jonatasbm
Problems when trying to collect data from a Json Web Service What I have tried: Hello good morning everyone, Sorry for my bad English. I'm trying to collect data from this Api ...
19 May 2020 by Richard Deeming
The value you're trying to deserialize doesn't match the JSON you've shown. To deserialize that JSON, your classes need to look like: Public Class Root _ Public Property OdataContext As Uri ...
22 Apr 2020 by S4753
Try to creating a JSON file using vb.net and json.net in windows application but unable to generate desired JSON file format. JSON format: { "CompCode": "COMP0001", "fp": "072018", "gt": 0, "cur_gt": 0, "b2b": [ { "patry": "ABC Company", "inv": [ { ...
21 Apr 2020 by Edgar Cortes
Before making your request, you may write the following: System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
31 Mar 2020 by Lupu5R3x
This code works for me to access the Json. The classes: public class JsonObjectHolder { public string UpdatePack { get; set; } //public Dictionary { get; set; } public Dictionary...
31 Mar 2020 by Lupu5R3x
Hi Could any one point me in the direction on how to deserialize the json. { "UpdatePack":"updatePacks\/1585654836.pack", "Updates":[ { "Name":"MsgBoxEx", "version":"1.5.14.88", "ChangeLog":"BugFix: Form...
29 Mar 2020 by Afzaal Ahmad Zeeshan
You can read my article to understand how to work with JSON data in C#, From zero to hero in JSON with C#[^]. It gives you an overview of JSON data, Newtonsoft library for JSON handling and a bunch of other tips. Now as for the question and this...
24 Jan 2020 by Jaya vardhani M
I am trying to create the below json structure and wanted to keep appending values only under policy defination , but how do i store and add new values along with existing values ? can someone please provide sample c# or idea on how to do it ? How the output should look like { ...
13 Jan 2020 by PrafullaVedante
This utility downloads Google takeout images from the downloaded JSON files.
11 Nov 2019 by OriginalGriff
First off, your classes don't entirely match the JSON: if you add the appropriate curly brackets to your data to make it "valid JSON" and run it through a class generator: json2csharp - generate c# classes from json[^] then you get a load of "__invalid_type__" classes generated which means that...
11 Nov 2019 by Member 14067523
i have a json response this "data": { "123456": { "rtc": { "121": { "rpc": { "2342_R": [ { "contract_type": "b2c", "egc":...
8 Nov 2019 by deepak21188
You can use Newtonsoft.Json NuGet package. It contains a class JsonConvert which can serialize or de-serialize C# objects into JSON data. The code will look like below: public class Resource { public string public_id { get; set; } public string type { get; set; } ...
8 Nov 2019 by Member 14581222
Parse my below json in C# { "resources": [ { "public_id": "/OrderImages/MyImg/UploadImages/", "type": "upload", "created_at": "2019-07-10T11:14:42Z", "bytes": 2560250, "width": 2992, "height": 2000 }, { "public_id":...
6 Nov 2019 by RickZeeland
See example here: Working With JSON String In C#[^] If your needs are simple, you can also just use the string, see webrequest example here: How to post JSON to a server using C#? - Stack Overflow[^]
6 Nov 2019 by OriginalGriff
If you look carefully, you will find tools on the internet which will do that and create your classes for you - there are quite a few. I use this one: json2csharp - generate c# classes from json[^] which is free and gave me this set of C# classes: public class Resource { public string...
30 Oct 2019 by Kombassere
Dear all, Your help will be appreciate for this problem i have with asp.net core razor page. i have a razor page with a select list field. When an item is selected, i want to get the selected value as a find function parameter. The find function must bring back some values from the database...
30 Oct 2019 by Ronnie Faircloth
Were you able to come up with an answer for this? I seem to be having the same issue. My SelectListItem value is always being returned as 0 which isn't even in the options.
7 Oct 2019 by ksk
TestInfo node in the JSON does not match to the property TestInfoCollection. JsonConvert.DeserializeObject can leave reference type member properties null during deserialization without [JsonProperty] attribute on the property. Try this: 1. Synchronize the property name in the class and in the...
7 Oct 2019 by Paul Dietz
I’m attempting to deserialize the following Json string to c# .net class list collection, but the Jsonconvert.deserialize returns null. Can someone please explain to me what I’m doing wrong. string strjson = "{...
20 Sep 2019 by RickZeeland
Quote: Take a look at: JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^] and select SQL Table. Your JSON is probably a bit too complex for the website, try to simplify like this: { "details" : { "name":"Johnson, Smith, and Jones Co.", "amount":123456.78, ...
20 Sep 2019 by ahmed_sa
I need to make json string formate suitable to select statement as following : select FooterTable.LineNumber,FooterTable.ItemCode,FooterTable.Quantity,FooterTable.UniPrice,FooterTable.Total from MasterTable inner join FooterTable on...
24 Apr 2019 by Jihed Haj Ali
You can use sites like quicktype to generate your code from your JSON data. // // // To parse this JSON data, add NuGet 'Newtonsoft.Json' then do: // // using QuickType; // // var welcome = Welcome.FromJson(jsonString); namespace QuickType { using System; using...
24 Apr 2019 by Member 14202729
Hello folks, The exception I'm getting is as follows: "Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.IEnumerable`1 because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo fix this error either change...
22 Apr 2019 by F-ES Sitecore
Your data has a property called "result" which is an array so you need a class that reflects that. Something like class MyData { [JsonProperty("result")] public List Result { get; set; } [JsonProperty("success")] public bool Success { get; set; }...
11 Mar 2019 by Scimiazzurro
I'm making an application with C# and Mono framework (to make it compatible with Linux).In this app I'm using also the Json.NET library, but it doesn't seem to work with Mono because every time I try to start the application I get this error:Missing method .ctor in assembly...
11 Mar 2019 by AdamWhitehat
From the error, it sounds like it cannot find the DLL. Place the DLL next to your executable or run the command: sudo apt-get install Newtonsoft.Json and then I think the runtime will know where to look.
13 Feb 2019 by Paul Dietz
Why does jsoncovert deserialization return null? string strjson = "{\"testinfo\":" + "[{\"testid\":1,\"testshortdescription\":\"tanktest\",\"testlongdescription\":\"Tank Test \",\"testtypeid\":2,\"testlimitsid\":null}," + ...
13 Feb 2019 by OriginalGriff
Probably, your class names don't match. If I feed your JSON into a class generator (json2csharp - generate c# classes from json[^]) I get these: public class Testinfo { public int testid { get; set; } public string testshortdescription { get; set; } public...
12 Feb 2019 by Gerry Schmitz
The "case" doesn't match. The JSON element names are lower case; the class properties are upper case (the fields are lower case and not accessible).
9 Jan 2019 by ONeil Tomlinson
Hi have a scenario where i'm getting back json from an API that is using JsonAPI. the json returned can be of two formats as shown below. (simplified for this example) { "attributes":{ "AnimalType":"Lion", "Name":"lio", "Eats":"Meat" } } and ...
9 Jan 2019 by Graeme_Grant
I wrote an article to help with all different types of questions related to JSON deserialization. You can find the answer to your question in this article: Working with JSON in C# & VB[^]
6 Jan 2019 by Ravi Sharma 2
Dear team,I unable to send the Special Character on Joson Result through MVC3.My code is $.ajax({ url: "/ProxyMaster/AddProxyGroupMapping?jsonValue=" + strSelecteds + '&VendorId=' + hdnVendorId + '&hdncode=' + 'abcd#123', type: 'POST', ...