Click here to Skip to main content
15,891,529 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 Title

JSON.NET 

30 Mar 2015 by star_tasneem
want to dynamically populate dropdownlist. have table of District{district_id,distrint_name} and Thana{thana_id,thana_name,district_id(fk)}.The controller code:public class CenterController : Controller { string connection...
10 May 2015 by rupai99
Hi, I need to Send and Receive JSON objects to Web Service Methods using jQuery AJAX in ASP.NetBut when ever I am executing the below code, getting [object Object] error. Please help.Html code:- ...
10 May 2015 by F-ES Sitecore
Use the browser's dev tools (f12) or Fiddler to examine the network traffic as it will often reveal the actual error. You need to mark your webservice as a script service[System.Web.Script.Services.ScriptService]public class testservice : System.Web.Services.WebService{ ...
12 Jun 2014 by M.Thiyagaraja
Quote:I am using Visual studio 2010. I am trying to add a reference 'Newtonsoft.Json.dll'. but error has come as this is not a COM component.How to add Quote:Newtonsoft.Json.dll, How to resolve this problem. When i try to add that dll in webservice Quote:error has come as this is not a COM...
12 Jun 2014 by Sergey Alexandrovich Kryukov
Most likely, you are talking about Newtonsoft.JSON: http://json.codeplex.com[^].If so, just look at the title:CodePlex says:Json.NETJson.NET is a popular high-performance JSON framework for .NETIt is not supposed to be anything like COM. You can expect that you are dealing with a .NET...
27 May 2015 by Imran Khan Hunzai
AJAX call is not working in IIS 7 and windows 7, the same application is running in XP and IIS 5.Please help me out.Here is the sample code function UpdateSLDataByRow(strWebServicePath, strServerKey) { alert("Update SL Data by row called"); $(function() { ...
24 Jul 2014 by KesaVan_K7
I am trying to Embed the url link from a Json to angularJs.Now i have the {{video.youtubeid}} with the output in Json controller has _kux-YQujjMBut when i use to call this function inside , it is not working.when i use this function inside P tag it show the output as...
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.
10 Jun 2016 by Osama Elsayed
first name last name
10 Jun 2016 by F-ES Sitecore
Using jQuery ajax to call asmx webservice methods | The ASP.NET Forums[^]Google "call web service ajax" and you'll find plenty more examples.
10 Jun 2016 by Karthik_Mahalingam
Try this,underline codes are corrected$.ajax({ type: "POST", contentType: "application/json; charset=utf-8", url: "http://localhost:4780/WebServiceRegistering.asmx/Registering", data: "{ 'Id': 8 }", ...
20 Feb 2015 by Sudheer Kumar Tiwari
How we can assign different name for property during serialization in JSON.Eg. My class have following structurepublic class std{ public int no {get;set;} public string name {get;set;} public string add {get;set;}}During json serialization (at run time) i wants name s1...
26 Sep 2014 by Member 7483521
Hi,In my REST Controller I have a HTTP/PUT handler method. The issue is that when I receive updates, I do not want to send everything over the wire if only one property has changed.The way I do it now is having the handler accept a dynamic parameter, which I then apply to my LINQ objects...
4 Dec 2014 by Santiago Fabian
Hello,I am making a HTTP Request to a Third Party API which one gives me a response in JSON format of type Newtonsoft.Json.Linq.JObject;My question is how to bind in some way an ASPxGridview Control from server side using C# with this JSON?
3 Oct 2015 by Aqib Shehzad
I want to bind Json.net serialize data which is in JSON format to tree from client side jquery.Can anyone help me to do by giving plugin link or any jsfiddle link.
4 Oct 2015 by Krunal Rohit
jsTree[^] it is.-KR
8 May 2015 by _Noctis_
This will allow you to integrate your linqpad code easily to Visual Studio
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...
5 Nov 2021 by Richard MacCutchan
See NewtonSoft Introduction[^]
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 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
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...
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" }, { ...
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...
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...
27 Jul 2017 by mridulkoul123
I am trying to parse a multilayer json from url and then the parsed json rootobject in datatables for insert and update command in c#. By far its inserting values into database but what i need is that this below code should first get convert into datatable var table =...
26 Jul 2017 by Graeme_Grant
If you are having problems with converting the raw JSON, then pass the raw JSON data to JSON Utils: Generate C#, VB.Net, SQL Table, Java and PHP from JSON[^] and it will generate the C# class files for you. A DataTable is a "Flat View" and your data is not flat, it has multiple layers. If you...
26 Jul 2017 by BillWoodruff
The error message is very clear: RootObject causes an error because 'RootObject is not a generic Type. You need to first get your JSON result (string), then use the Newtonsoft.Json.Converters.DataTableConverter class facilities to convert it to a DataTable [^]. It's important, if...
2 May 2014 by vaeaze
In the view I want to get the json data like this: [{"name":"NewWork", "data":[{"\/Date(1398787200000)\/",196}, {"\/Date(1398009600000)\/",62}, {"\/Date(1397836800000)\/",65}] }, {"name":"BeiJing", ...
31 Oct 2014 by Satheesh Santhosh
Using a xamarin cross platform development to i want print a json message from url and print in listview. I write code without error but with some mistakes. I will not work. For just a verfication output only i print the button in the output screen. I will shown but the listview was not print....
31 Oct 2014 by BillWoodruff
As I explained to you in this solution to your previous question [^]:You must provide a valid class structure to use JSON de-serialize on Web data, and that structure will almost certainly be different for each web-site that provides JSON you can grab.And, since any given web-site may...
27 May 2014 by Yagnik_Vishal
My jstree bind with following json format comes from web service..i want to change node color programmatically. $("#divCourseTree").jstree({ 'core': { 'data': { 'type': "POST", ...
23 Oct 2013 by Jocelyne El Khoury
I have this function in ASP.NET to convert a DataTable to JSON string:Public Function GetJson(ByVal dt As DataTable) As String Dim serializer As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer() Dim rows As New List(Of...
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[^]
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...
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...
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...
21 Mar 2015 by anurag19289
My Json is...
21 Mar 2015 by Sergey Alexandrovich Kryukov
Please see my past answers:How To Convert object type to C# class object type[^],how to conver multi level json data to C# Object?[^].—SA
29 Nov 2017 by Shamina Maharaj
Hi Guys, I'm a Visual FoxPro developer, migrating to C#. I'm currently developing a credit check app using web references. The response I get is in JSON and I'm trying to convert it to xml. The problem I get is that newton soft doesn't want to convert a JSON string/list/non-object to C#. Please...
29 Nov 2017 by F-ES Sitecore
That's pretty complex JSON to interpret, and not particularly well designed in my opinion. I think it'll be hard to get something to convert that to XML automatically in a format that is going to look decent, you might need to do some of your own parsing of the data. This might get you started...
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": [ { ...
1 Sep 2018 by Graeme_Grant
I wrote an article to help answer questions commonly asked in here: Working with JSON in C# & VB[^] Your question is about serialization of class to raw JSON, something not covered in detail in the article, so I will answer here using Newtonsoft's Json.NET[^] library. To make sure that your...
8 Mar 2017 by Amien90
public class RootJson{ public string App { get; set; } public List ListSourcesFile { get; set; }}public class SourcesFile{ public string Source { get; set; }}This is my rootNow: RootJson rootjson = new RootJson() rootjson.App =...
7 Mar 2017 by Richard Deeming
The first problem is that you haven't initialized the list, so rootjson.ListSourcesFile returns null, and any attempt to index into the list throws a NullReferenceException.The second problem is that you haven't added anything to the list. When you try to retrieve the first item of an empty...
8 Mar 2017 by Amien90
RootJson rootjson = new RootJson{ App = appIdentifier.AppName, ListSourcesFile = new List { new SourcesFile { Source = "Fdf", }, new SourcesFile { Source = "Sdr", }, },};or:SourcesFile...
12 Feb 2014 by rishiraj malvi
Hello Everyone, I have classes in my application generated by Json :-public class Answer { public string answerId { get; set; } public string answer { get; set; } }public class Question{ public string questionId { get; set; } public string questionTitle { get; set; } ...
12 Feb 2014 by hitech_s
Use observable collections of questions and bind to the ui.after finishing all the questions user will hit submit button there you just read the observable collection it contains the answers selected by the user.
17 Feb 2014 by rishiraj malvi
it get all the question & option on next button by declaring List question and get all values from obj of main.
1 Dec 2014 by Dhiraj Bhole
I am looking for demos, sample code and tutorial about JSON.NET. I would prefer demonstrations ready to use.
1 Dec 2014 by /\jmot
See..Use C# to get JSON Data from the Web and Map it to .NET Class => Made Easy![^]https://www.udemy.com/blog/c-sharp-json/[^]http://msdn.microsoft.com/en-us/library/bb299886.aspx[^]
1 Dec 2014 by Mukesh Pr@sad
Hi Dhiraj,Go through the following...
1 Dec 2014 by Mathew Soji
Checkhttp://james.newtonking.com/json/help/index.html[^]http://james.newtonking.com/json[^]http://stackoverflow.com/questions/tagged/json.net[^]
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[^]
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, ...
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;...
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...
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...
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...
19 Dec 2013 by Member 10336798
Hi, im trying to deserialize the following JSON String:http://docs.ninja.is/rest/device.html#device-get-devices[^]{ "result": 1, "error": null, "id": 0, "data": { "ASTEALTHYNODE01_0301_0_30": { "css_class": "sensor rf digital humidity", ...
20 Dec 2013 by Sunny_Kumar_
You go ahead and use Json.Net to deserialize this JSON, it's deserialized very well.check it here:[^]is not working well... check out this one:http://json.parser.online.fr/[^]HTH!
9 Jan 2018 by Member 12144890
I am new in json. In my project i need to deserialize json data come from amazon service url . this is my json format json list
9 Jan 2018 by Karthik_Mahalingam
try dynamic _userin = JsonConvert.DeserializeObject(json); foreach (var item in _userin) { string name = item.Name; string time = item.Value.time; string type = item.Value.type; string bounceType = item.Value.bounceType; ...
16 Nov 2022 by Graeme_Grant
How to deserialize very large simple & complex JSON Streams (.NET 6.0 & 7.0)
11 Aug 2015 by Saeed Jafarian
Helloi am working on a C# web application in which i have to save and restore the state of the application, i am doing this by serialization and deserialization. every thing works fine but the problem is when i deserialize list in which the object has a property from other class , then...
11 Aug 2015 by Sergey Alexandrovich Kryukov
Saeed Jafarian wrote:so if i use DataContractSerializer the problem should be solved, i don`t have problem with switching, i have tried 3 types of serializer up to now.i will try and make you know if this worksIf you do it, the problem will be sorted by using this:...
16 Oct 2016 by Member 12794117
Hi,I am very new to web development and I am developing a web app using ASP.NET MVC 5.I have a requirement to deserialize a json string and store the values in C# ObjectsThis is how my JSON looks like{ "spellCheckQuery": "abc*", "searchStatus": "OK", "results": [ { ...
16 Oct 2016 by F-ES Sitecore
dobj.results should be a list of two result objects so you can use that as a datasource for your objects, or show them in a view like@foreach(var result in Model.results){ // your html here @result.id}
29 Jan 2015 by Dinesh92d
in Maths Graph Sheet to Develop my Project How to Get X y Coordinates on tooltip? Before we are using clientX its not perfect only gets Pixcel res...I want to have graph value on tooltip its possible?
4 Aug 2013 by Vitaly Tomilov
Using JSON.NET to deserialize collections of dynamic-type objects.
31 May 2016 by Hamid Mosalla
Dynamically building JSON tree for use In JavaScript components using C#
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 { ...
16 Mar 2017 by Robert Bettinelli
Easy JSON Recursion in VB.NET with nested levels
6 Mar 2017 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.
22 Oct 2013 by Jocelyne El Khoury
i am receiving through http post the following string as json: Dim json As String = "[{" + """name"":""jocelyne" + """," + """mo"":""jocelyne" + """}" + ",{" + """name"":""eliane" + """," + """mo"":""12345678" + """}" + "]"i need to convert this json array to a datatable in vb.neti...
22 Oct 2013 by Jocelyne El Khoury
i fixed it :i'm trying to deserialize the JSON string into a Dictionary which should represent an object, but my JSON string contains an array of two objects instead of a single object.So ishould use List(Of Dictionary(Of String, String)) instead of Dictionary(Of String, String):Sub...
27 Oct 2014 by Naina2
In the code , i m getting this error :'System.Collections.Generic.KeyValuePair' does not contain a definition for 'detail'here is the code : dynamic friendList = fb.Get("me/friends?fields=id,first_name,last_name,birthday,location,locale,age_range"); ...
16 Oct 2013 by Jocelyne El Khoury
i'm trying to read a json string from an http post, i'm trying to test my code by filling the json string manually but my problem is that i'm not able to add the same node many times.... in other words if i put the following it works: Dim json As String = "{'name': 'jocelyne','mo':...
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; }...
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...
9 Mar 2017 by TarunSingla
How to extract field names from json?
12 Jun 2018 by Member 13801408
string msdg = "{"EventTimestamp":"2018-06-08 00:11:26,070", "Level":"INFO", "RouteId":"PubSubV2DistRoute", "ActivityTimestamp":"2018-06-07T23:13:50.363097Z", "SrcSys":"", "ShrActNr":"W0980X", "DtnCnyCd":"DE", "DtnFacMnm":"DESCK", "DtnSlicNr":"0445", "OrgCnyCd":"JP", "OrgFacMnm":"JPSHN",...
12 Jun 2018 by Afzaal Ahmad Zeeshan
First of all, that code won't compile as it is, even if you manage to have it compiled — by adding a @ at the beginning of string — you would need to just call the property Message and get everything you need. What was too difficult in that? dynamic obj = JsonConvert.DeserializeObject(msdg); ...
1 Dec 2014 by vijaykittur
Hi All,I have one big string,in that i have embedded json date format like(\/Date(1425321000000+0530)\/) in many places in my original string.I need to convert this format to normal readable format.RegardsVijay
1 Dec 2014 by Mukesh Pr@sad
Hi Vijay,Go to the below link:-http://codeasp.net/assets/demos/blogs/convert-net-datetime-to-javascript-date.aspx[^]Thanks,Mukesh
29 Aug 2017 by eagers
I want generate json schema from json datafile, like below.(this is generated with online tool, http://jsonschema.net/) is it possible with JSON.NET or any other?{ "graph": [ { "id": 453, "cid": 143, "title": "graph1", "description": "", ...
17 May 2015 by Sergey Alexandrovich Kryukov
Please see: https://sixgun.wordpress.com/2012/02/09/using-json-net-to-generate-jsonschema[^].You should understand that generating metadata from data can be ambiguous; it depends on how representative your data sample is.[EDIT]My last paragraph above suggests that this approach may...
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; }...
26 Dec 2016 by robert_chang
Learn how to connect to Dynamics CRM, customize and query Customer Address entity, geocode the address and update CRM data.
28 Oct 2014 by Shamas Imran, Muhammad N@beel
Convert Coordinate data to strings to be stored in database.
2 Feb 2016 by Rahul Anand Jha
I have tried hard but failed to detect the error due to which my method "getmyCoordinates(string address)" always returns data with geometry nullusing System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Net.Http;using...
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...
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 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...
25 Dec 2015 by Tadit Dash (ତଡିତ୍ କୁମାର ଦାଶ)
In this blog, I will tell you the trick to convert JSON string property to C# Object using Newtonsoft.
17 Nov 2014 by User 9972772
Hi All,I am trying to display google map in master page.But map was not loading only empty page was displaying.Please find my code below: