tagged [system.text.json]

How to configure a default JsonSerializerOptions (System.Text.Json) to be used by Azure Function v3?

How to configure a default JsonSerializerOptions (System.Text.Json) to be used by Azure Function v3? I have a set of Azure Functions v3 running on .net core 3.1. I have a custom configuration of `Json...

System.Text.Json: Deserialize JSON with automatic casting

System.Text.Json: Deserialize JSON with automatic casting Using .Net Core 3's new System.Text.Json JsonSerializer, how do you automatically cast types (e.g. int to string and string to int)? For examp...

Equivalent of JObject in System.Text.Json

Equivalent of JObject in System.Text.Json I have DTO class that has a property of type `JObject`. This DTO class is send/receive over HTTP between multiple services. JObject is used because the `Extra...

17 Aug at 13:55

Converting newtonsoft code to System.Text.Json in .net core 3. what's equivalent of JObject.Parse and JsonProperty

Converting newtonsoft code to System.Text.Json in .net core 3. what's equivalent of JObject.Parse and JsonProperty I am converting my newtonsoft implementation to new JSON library in .net core 3.0. I ...

How to deserialize an empty string to a null value for all `Nullable<T>` value types using System.Text.Json?

How to deserialize an empty string to a null value for all `Nullable` value types using System.Text.Json? In .Net Core 3.1 and using `System.Text.Json` library, I'm facing an issue that didn't occur i...

25 Mar at 14:51

AddNewtonsoftJson is not overriding System.Text.Json

AddNewtonsoftJson is not overriding System.Text.Json I have upgraded my version of .Net Core from preview 2 to preview 6 which has broken a couple of things. Most significant is that I cannot use newt...

System Text JsonSerializer Deserialization of TimeSpan

System Text JsonSerializer Deserialization of TimeSpan In researching how to deserialize a `TimeSpan` using Newtonsoft's JSON.net I came across code in my current project that did not use Json.net. It...

dynamic c# ValueKind = Object

dynamic c# ValueKind = Object As i'm trying to access using using debugger. [](https://i.stack.imgur.com/NaMXf.png) Here is my result which i'm having below. As i try to access it using `var Data = J...

27 Jul at 19:42

How do you read a simple value out of some json using System.Text.Json?

How do you read a simple value out of some json using System.Text.Json? I have this json How do I get the `48e86841-f62c-42c9-ae20-b54ba8c35d6d` out of it? All examples I can find show to do something...

27 Nov at 05:26

System.Text.Json.JsonException: The JSON value could not be converted

System.Text.Json.JsonException: The JSON value could not be converted I'm using Ubuntu and dotnet 3.1, running vscode's c# extension. I need to create a List from a JSON file, my controller will do so...

8 Feb at 18:44

What is equivalent in JToken.DeepEquals in System.Text.Json?

What is equivalent in JToken.DeepEquals in System.Text.Json? I want to migrate my code from Newtonsoft Json.Net to Microsoft standard System.Text.Json. But I could not find an alternative for `JToken....

29 Mar at 03:3

How can I parse JSON with comments using System.Text.Json?

How can I parse JSON with comments using System.Text.Json? I have some JSON that includes comments (even though comments aren't strictly allowed in the [JSON spec](https://www.json.org/json-en.html).)...

22 Dec at 22:18

Each parameter in the deserialization constructor on type must bind to an object property or field on deserialization

Each parameter in the deserialization constructor on type must bind to an object property or field on deserialization I have the following simple classes : ``` public abstract class GitObject { publ...

5 Jun at 19:24

ASP.NET Core 3.0 System.Text.Json Camel Case Serialization

ASP.NET Core 3.0 System.Text.Json Camel Case Serialization In ASP.NET Core 3.0 Web API project, how do you specify [System.Text.Json](https://learn.microsoft.com/en-us/dotnet/api/system.text.json?view...

18 Dec at 15:27

JsonSerializer.Deserialize fails

JsonSerializer.Deserialize fails Consider the code... ``` using System; using System.Text.Json; public class Program { public static void Main() { int id = 9; string str = "{\"id\": " + id...

How to globally set default options for System.Text.Json.JsonSerializer?

How to globally set default options for System.Text.Json.JsonSerializer? Instead of this: I would like to do something like this: ``` // This property is a pleasant fiction JsonSerialize

Modifying a JSON file using System.Text.Json

Modifying a JSON file using System.Text.Json I know you can do this easily with Newtonsoft. As I am working with .NET Core 3.0, however, I am trying to use the new methods for interacting with JSON fi...

System.Text.Json - Deserialize nested object as string

System.Text.Json - Deserialize nested object as string I'm trying to use the `System.Text.Json.JsonSerializer` to deserialize the model partially, so one of the properties is read as string that conta...

System.Text.Json Field Serialization in .NET 5 not shown in Swashbuckle API Definition

System.Text.Json Field Serialization in .NET 5 not shown in Swashbuckle API Definition # Problem I'm using ASP.NET Core with .NET 5 and am using the `System.Text.Json` serializer to serialize types co...

Getting nested properties with System.Text.Json

Getting nested properties with System.Text.Json I am working with `System.Text.Json` in my project as I am processing large files so also decided to use it for processing GraphQL responses. Due to the...

2 May at 06:45

How to handle both a single item and an array for the same property using System.Text.Json?

How to handle both a single item and an array for the same property using System.Text.Json? I am trying to deserialize some JSON that contains a value that is sometimes an array, and sometimes a singl...

20 Dec at 19:59

Parsing a JSON file with .NET core 3.0/System.text.Json

Parsing a JSON file with .NET core 3.0/System.text.Json I'm trying to read and parse a large JSON file that cannot fit in memory with the new JSON reader `System.Text.Json` in .NET Core 3.0. The examp...

System.Text.JSON doesn't deserialize what Newtonsoft does

System.Text.JSON doesn't deserialize what Newtonsoft does I have a json that the new `System.Text.Json.JsonSerializer.Deserialize(json_data)` serialize as `List` with the correct numbers of elements, ...

27 Nov at 04:24

Dynamically ignore property on sealed class when serializing JSON with System.Text.Json

Dynamically ignore property on sealed class when serializing JSON with System.Text.Json ### Question Can I dynamically ignore a property from a sealed class using [System.Text.Json.JsonSerializer](htt...

DateOnly Json Conversion in .net6 api

DateOnly Json Conversion in .net6 api How can I add the DateOnly JsonConverter to the application configuration of a .net6 web api? I have an object with DateOnly properties on it and I'm returning it...

3 Nov at 20:0