Questions tagged [json.net]

Json.NET (also known as Newtonsoft.Json) is a popular high-performance JSON framework for .NET.

Filter by
Sorted by
Tagged with
0 votes
1 answer
58 views

Serialized JSON is not deserializing

I've got some JSON code I'm embedding in a JSON object that I use JsonConvert . SerializeObject ( ) to properly escape for myself, then I promptly try JsonConvert.DeserializeObject ( ) and get an ...
Janzstone's user avatar
0 votes
0 answers
56 views

C# Special character in Json read from file, specially Quote " throws exception when deserializing

I have to read json from a downloaded files which has the following Json { "configuration": { "aboutDisplayServerName": false, "aboutText": "This ...
Zaveed Abbasi's user avatar
1 vote
1 answer
74 views

Convert JArray to list, keeping only one nested JToken

I have a JArray that looks like this: [ { "1": "A", "2": "B", "3": { "5": "D", ...
Traceur's user avatar
  • 53
-3 votes
0 answers
77 views

How Can I Parse This Jagged JSON string in C#? [closed]

I am attempting to return the value of the "key" field in the following string in C#. Tried a few ways to transform into a JSON object and then parse but so far no luck: { "Records&...
Rez Khan's user avatar
-1 votes
0 answers
77 views

NewtonSoft JSON.NET does not serialize properties [closed]

Sample code: public class DerivedClassEventArgs : BaseEventArgs { public String Name { get; private set; } public bool Age { get; private set; } } public class BaseEventArgs : EventArgs ...
Loch's user avatar
  • 85
-3 votes
0 answers
30 views

I'm getting a Json response but can't read it, escaping? [closed]

C# I give a simple request, but I get this response. I think the whole example is not necessary, everything seems clear. And I think this is a shielding problem. HttpResponseMessage response = await ...
Vladimir's user avatar
-1 votes
0 answers
24 views

JSon.Net deserialization error. NullReferenceException: Object reference not set to an instance of an object [duplicate]

I am working on a complex save system in Unity using Json.Net. When deserializing I get this error: Error: Error deserializing WizardTower.Tile. Object reference not set to an instance of an object. ...
WVrock's user avatar
  • 1,733
0 votes
1 answer
33 views

ASP.NET Core OData response json serialization nullvalue handling

Consider two endpoints exposing data as OData. The first in an ODataController: private static readonly string[] Summaries = new[] { "Freezing", "Bracing", "Chilly", &...
Jimmy Hannon's user avatar
-1 votes
1 answer
42 views

How to deserialize an object based on a text property using Newtonsoft

JsonConvert.DeserializeObject(json) Is returning a set null objects. I've tried making the objects not descendants of Widget. Then I'm getting an error The value "Widget2" is not of type &...
BermudaLamb's user avatar
1 vote
2 answers
67 views

How to use the null conditional operator on a C# dynamic ExpandoObject property chain

I am working with a JSON object with a few different possible structures and want to elegantly extract a value from a few possible paths. e.g. my dynamic object has a name under one of these paths ...
Moffen's user avatar
  • 1,857
1 vote
1 answer
68 views

Why is my custom Json.net converter not working?

Since GameObjects cannot be serialized I wrote a class that holds the name of the GameObject so that it can find it by the name. However I am getting this error during deserialization and I can't ...
WVrock's user avatar
  • 1,733
2 votes
1 answer
67 views

When `JToken?` is null?

Iterating through json Im using Newtonsoft.Json: var jObject = JObject.Parse(sr.ReadToEnd()); foreach (KeyValuePair<string, JToken?> superior in jObject) { ... } As you can see above, JObject ...
VladisS's user avatar
  • 67
0 votes
0 answers
34 views

Refit.ApiException at System.Text.Json.Serialization.JsonCollectionConverter

I am using Refit to call APIs in .NET 7.0 System.Text.Json.Serialization.JsonCollectionConverter throws exception when the response returned in empty. It works fine when result contains data. I think ...
Hakuna's user avatar
  • 297
-1 votes
0 answers
61 views

C# Serialize and Deserialize Base Classes with Common Data to separate JSON files/sections

I'm trying to store some definition information where each definition inherits common data from base classes. Instead of serializing the common data for each definition I would like to store it just ...
Niska's user avatar
  • 9
0 votes
1 answer
41 views

C# Newtonsoft Deserialize JSON with items vs array?

I am struggling on trying to deserialize a JSON string: { "status": "success", "result": { "campaigns": { "1000" : { &...
Joe's user avatar
  • 3
0 votes
1 answer
64 views

.NET. Mail not sent any attached files with two step verification on office 365

I send emails without problem using this .Net program, but if I attach a file it never arrives. In the mail server appears that the mail has arrived correctly, but that it does not include any ...
JavierB's user avatar
0 votes
0 answers
41 views

Unable to JsonConvert.DeserializeObject that is a list of just JSON objects no [] [duplicate]

Using .Net C# and Newtonsoft JSON I'm having considerable trouble deserialising a list of JSON objects from a vendor API that are not in an array or , delimited. I'd like to deserialise them into a ...
bandworthy's user avatar
3 votes
2 answers
55 views

How Can I Deserialize and Get the values from the ReportData Node in C#?

I have to parse an deserialize all the values from the following JSON file: But I'm getting errors from the compiler. [ { "CompanyInfo": { "Company": &...
Arturo Martínez's user avatar
0 votes
1 answer
37 views

JTokenType for null string JValue does not match other null JValues

I was comparing JTokens with JToken.DeepEquals() for test code when I encountered a failing test that troubled me: testResult: { "str": null, "int": 1 } // Child of a larger ...
Matthew Tenczar's user avatar
0 votes
1 answer
105 views

Issue with Newtonsoft JSON Serialization to Lower Camel Case

I'm currently facing difficulties in converting object properties to lower camel case using Newtonsoft JSON serialization in C#. Here's a simplified version of the code I'm using: [JsonObject(Title = &...
bilpor's user avatar
  • 3,575
1 vote
1 answer
44 views

C# Remove object from JSON with nested property [duplicate]

I have this JSON, and I want to delete "delta" section with all nested property. I already use JObject.Remove("delta") but I have this error: Cannot add or remove items from ...
user1018379's user avatar
0 votes
1 answer
37 views

JwtSecurityToken.WriteToken causes "The type initializer for 'System.IdentityModel.Tokens.Jwt.JsonExtensions' threw an exception."

The following code gives me this error: The type initializer for 'System.IdentityModel.Tokens.Jwt.JsonExtensions' threw an exception. handler = new JwtSecurityTokenHandler(); tokenStringEngineer = ...
Sonnich Jensen's user avatar
0 votes
1 answer
50 views

Deserialize JSON and adding back into DataTable with main records

I have a DataTable and it has some JSON data, I want to deserialize the JSON, and add it to the primary record. JSON columns can be none or many. If the column has JSON data, I am fetching and adding ...
SU_Khan's user avatar
  • 23
1 vote
1 answer
56 views

How to invoke JsonConverter from inside other JsonConverter?

I'm trying to parse each step based on the command field. For that I decided to delegate the parsing to specific convertor inside CustomElementJsonConverter::ReadJson which is created using a factory. ...
theateist's user avatar
  • 14k
0 votes
1 answer
55 views

Deserializing JSON with multiple elements of the same type with different name

I am attempting to deserialize some json into a custom object in VB.net 4.5 The Json structure can have multiple elements with different names, and the names may not be the same so I can't create a ...
NapkinBob's user avatar
  • 644
0 votes
1 answer
38 views

How Could Disconnect From Local JSON File?

I need to download every 10 minute a JSON file in to my project. (Older file delete and new file replace it) and between delete and replace last process read data from data with newtonsoft.json ...
Vahid Bahrami's user avatar
0 votes
1 answer
71 views

Serialization and Deserialization HttpClient payload in C#

I have to retrieve some verbose json data from an API using System.Net.Http.HttpClient. In order to correctly deserialize these data in the desired format I have to remove white spaces and special ...
GIovanni's user avatar
0 votes
2 answers
132 views

Newtonsoft json: serialize values in object as dictionary keyvaluepair

I have an anonymous object like: string keyValue = "keyValue1"; var itemsArray = new [] { .. } return new { Key = keyValue, Items = itemsArray } That I want to serialize to a string ...
dododo's user avatar
  • 4,284
0 votes
1 answer
69 views

CosmosSerializer custom json serialization to trim string values

I am attempting to create a custom CosmosSerializer that trims all whitespace from property values during both serialization and deserialization (both reading from and writing to a cosmos container). ...
ben's user avatar
  • 13
0 votes
1 answer
57 views

JsonConvert.SerializeObject Removes Columns From Empty Datatable

I am using JsonConvert.SerializeObject to serialize DataSets. Occasionally, DataTables within my DataSet don't have any rows, but the DataTable does have columns. When I serialize the DataSet if a ...
LongNeckTimmy's user avatar
0 votes
0 answers
34 views

JSON library version mismatch

Every Newtonsoft.Json.dll reference in projects, has maximum version of 12.0.3. In builded bin folder, in app.exe.config there is <dependentAssembly> <assemblyIdentity name="...
Jan J.'s user avatar
  • 45
0 votes
1 answer
86 views

C# - Having trouble iterating over a dynamic JSON

I am trying to pull JSON data from a website and I am having some trouble iterating over the objects it returns. Can someone please assist with navigating this structure? I am confused by it not being ...
eek's user avatar
  • 708
0 votes
2 answers
32 views

.NET JSON: check structure

I know I can check wether is a string is a valid JSON-formatted string using parsing functions and catching exceptions. But what I need is a bit more than that too. I need to check if a string that ...
Wouter Vandenputte's user avatar
1 vote
0 answers
64 views

Newtonsoft JSON deserializer error when receiving a string that is a 36 digit number [closed]

I have a ProposalData class set up in a C# program. The program reads a JSON string and tries to deserialize it to an instance of the ProposalData class. Everything has been working well for years, ...
Mark Frasier's user avatar
0 votes
1 answer
56 views

How generate the desire output

My client api is expecting the below format { "foo": [ { "bar": { "firstname": "Jason", "lastname": "Long", ...
King S's user avatar
  • 1
0 votes
1 answer
81 views

how to deserialize a json object with different outcomes

When I call a web api, I got either a normal object or an error object (If an error occurs) like below; { "fault": { "correlationId": "ea0323ad-8883-47e6-bcc7-...
Bernard Black the Second's user avatar
0 votes
1 answer
23 views

Error with OkObjectResult and json string when moving from a FunctionApp to ASP.NET Core WebAPI

I had a function app in C# that made a function call to a stored procedure and returned the results as follows: connection.Open(); SqlDataReader reader = command.ExecuteReader(); var dataTable = ...
John Zanni's user avatar
-1 votes
1 answer
106 views

Check if a object exists in a array in c#

I have a json-string looking like this; { "products": [ { "location": "City 1", "name": null, "serial": "1412234-...
Tomas H's user avatar
  • 63
0 votes
0 answers
34 views

NewtonSoft.Json usign camelCase when it shouldnt - machine dependent?

Serializing problem It seems like NewtonSoft.Json outputs different Json based on the machine. But only for a single property The difference and curios thing is that any key in Settings gets converted ...
Daniel Pace's user avatar
0 votes
0 answers
70 views

How To Deserialize a JSON Object Polymorphicly?

I am attempting to deserialize data from an API in JSON format. There are four different queries I am making to get data. They are as follows: GetDatasetlist, GetParameterList, GetParameterValues, and ...
David Hill's user avatar
0 votes
0 answers
24 views

C# Newtonsoft Custom Serializer + ContractResolver not being called. [ElasticSearch]

This error occurs when serializing some EntityFramework models in order to send them to ElasticSearch. I'm using a custom serializer + custom contract resolver derived from those classes: ...
Cata's user avatar
  • 29
0 votes
1 answer
32 views

Unable to view the news list (data type) in the news app

We're using the news app in 2sxc and it works fine, we can add and edit articles. However when we use the manage articles link ("contentitems?contentType=News"). It seems there is some ...
MBouwman's user avatar
0 votes
0 answers
27 views

Deserialize property basing on another property

The problem we are having is that our request model contains numerous properties of type DateTime. We need to be able to know what was the original timezone we have received in the request however as ...
MajkeloDev's user avatar
  • 1,661
-4 votes
2 answers
45 views

Newtonsoft.Json - Does it communicate over internet

We use the library Newtonsoft.Json in our project and based on a customer request we are trying to figure out If the library communicates over to Internet any time during the course of operations? It ...
Harshvir's user avatar
0 votes
0 answers
69 views

JSON.NET when ToObject can return null

This is the method signature of ToObject<T>(). Notice that it returns nullable T. I am wondering given what JObject value the ToObject will return null. public T? ToObject<T>() { ...
Node.JS's user avatar
  • 1,099
1 vote
1 answer
68 views

Enum string serialization not working as expected in .net 6.0

I have a production api returning the below json: [ { "StartUtc": "2023-09-02T13:52:00Z", "EndUtc": "2023-09-02T15:19:00Z", "...
user007's user avatar
  • 1,566
0 votes
2 answers
52 views

How to set indent distance when saving a dict to a JSON file in C#.Net?

I use Visual Studio 2022 and download Newtonsoft.Json in NuGet package manager, my dict like: var param_dict = new Dictionary<string, object> { { "config_path", "D:\WORK_2023\...
4daJKong's user avatar
  • 1,907
-1 votes
1 answer
29 views

Newtonsoft JObject adding newline characters when converting to string [duplicate]

I have a C# program that adds properties to a JObject but when I convert to string, it has \r and \n characters in the output. I'm using a very simple example with only the name and value: JObject jo ...
Velocedge's user avatar
  • 1,230
0 votes
2 answers
59 views

JSON Deserializer not working for nested object

I have an application that serializes an object and sends a JSON string value as below. public class Rootobject { public int MessageState { get; set; } public object Message { get; set; } ...
user14267126's user avatar
0 votes
0 answers
48 views

How to set class properties that are dependent on other properties when deserializing JSON

I have a class with a structure similar to this public class TestClass1 { public TestClass1() { } private string _name; public string ScriptName { get; set; } public ...
ilya_i's user avatar
  • 333

1
2 3 4 5
274