Questions tagged [system.text.json]

System.Text.Json is the built-in JSON facilities added in .NET Core 3.0.

The System.Text.Json namespace provides high-performance, low-allocating, and standards-compliant capabilities to process JSON, which includes serializing objects to JSON text and deserializing JSON text to objects, with UTF-8 support built-in. It also provides types to read and write JSON text encoded as UTF-8, and to create an in-memory document object model (DOM) for random access of the JSON elements.

Additional details can be found in the how to article.

973 questions
0
votes
1 answer

C# System.Text.Json Deserializing when the response format changes due to flags in the request

I'm trying to consume a vendor's api using c# and System.Text.Json. Some API calls allow for flags in the request that add sections to the response. I'm not sure how to handle these (lack of experience). I can send and receive no problem to…
Hecatonchires
  • 1,009
  • 4
  • 13
  • 42
0
votes
1 answer

BigInteger with system.text.json

I am pulling data from a public api which I do not control. One object contains a property "space":40110198681182961664. This property is too large for an ulong. The correct value type would be BigInteger. And here comes the issue. System.Text.Json…
julian bechtold
  • 1,875
  • 2
  • 19
  • 49
0
votes
1 answer

Deserializing JSON with UTC/Zulu Time String using System.Text.Json

I am having some issues deserializing JSON that has a Zulu formatted time string. I continue to receive an exception that states the string is not a data and time. I have the following string being returned from and REST service. { ".issued":…
Ducky
  • 11
  • 2
0
votes
0 answers

How can I exclude properties from JSON serialization using custom logic in System.Text.Json without using attribute?

I have an object that contains a Func property: public class Foo { public Func DoCalculation {get;init;} public string Bar {get;init;} } How can I exclude all Func<...> properties in any JSON serialization without using [JsonIgnore] or…
THX-1138
  • 21,316
  • 26
  • 96
  • 160
0
votes
0 answers

Get JSON descendants using System.Text.Json in C#

I have written following method to get JSON descendants using System.Text.Json: public static IEnumerable GetDescendants(this JsonNode jsonNode) { switch (jsonNode) { case JsonObject jsonObject: …
Szyszka947
  • 473
  • 2
  • 5
  • 21
0
votes
3 answers

Serializing object with System.Text.Json setting ReferenceHandler to ignore not working in .NET 7

I'm trying to serialize an object in ASP.NET Core MVC Web API into a JSON before returning it to the user. The object is from an EF Core database, and the controllers are generated using scaffolding with some include properties I've added which I'd…
0
votes
0 answers

Getting System.ArgumentException: An item with the same key has already been added while using System.Text.Json

I was trying to get a value from a json object during crawling data into SQL Server using System.Text.json. The json data's structure is like this: skus: 1v9beswiav1wo91j:{...,...} The key 1v9beswiav1wo91j is unreachabe to me, so I use JsonNode…
0
votes
2 answers

JsonSerializer.Deserialize always returns Null

Trying to deserialize the following json string: string json =…
0
votes
2 answers

How to add JsonPropertyName to inherited properties?

How do I deserialize json to my class that is inheriting from base class but properties in base class do not match json? I cant's control base class. For example: { "prop1": "Value1", "prop2": "Value2" } I want to deserialize above to…
Pawel
  • 891
  • 1
  • 9
  • 31
0
votes
1 answer

How do I deserialize NuGet.NuGetVersion into a class in C#?

I'm a beginner, just writing code for an application for my work and I was trying to deserialize a class, but encountered an error. I have a class named Nuget, that looks like this: public class Nuget { public string? Name { get; set; } …
0
votes
1 answer

How to set DisableSystemTextJsonSourceGenerator from build.props file?

I'm having the same issue reported here: https://github.com/dotnet/runtime/issues/61602#issuecomment-971824612 basically: trying to use System.Text.Json 6 in a dotnetapp3.1 application (which cannot be upgraded at the moment). This causes that the…
dmorganb
  • 1,408
  • 16
  • 26
0
votes
0 answers

System.Text.Json.ThrowHelper.ThrowJsonException_SerializerCycleDetected

I got this error: JsonException: A possible object cycle was detected. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 64. Consider using ReferenceHandler.Preserve on JsonSerializerOptions to…
pinale
  • 2,060
  • 6
  • 38
  • 72
0
votes
1 answer

Why is JsonSerializer.Deserializer only partially populating my object?

I have a class defined as follows: public class NearestLocation { public Int32 ID { get; set; } public String Name { get; set; } public String TypeID { get; set; } public String SourceID { get; set; } public String Code { get;…
ChrisH
  • 15
  • 4
0
votes
1 answer

What is the purpose of the `inputType` parameter of `JsonSerializer.Serialize`

System.Text.Json.JsonSerializer.Serialize is a set of overloads that serialize a C# object into json. The non-generic overloads all share three parameters - object? value which is the object to serialize; System.Text.Json.JsonSerializerOptions?…
Eamon Nerbonne
  • 47,023
  • 20
  • 101
  • 166
0
votes
1 answer

TypeInfoResolver Modifier doesn't resolve correct type - it resolves base type instead of real type

I have difficulty replacing Newtonsoft's ContractResolver with System.Text.Json TypeInfoResolver Modifier. I have a ContractResolver that is responsible for serializing only specific properties: public sealed class BaseExceptionContractResolver :…
Misiu
  • 4,738
  • 21
  • 94
  • 198