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
0 answers

Json Serializer - Serialize enum description instead of its value

READ BEFORE MARK AS DUPLICATED The "JavaScriptSerializer - JSON serialization of enum as string" question don't answer my question! I'm trying to serialize an enum but I want the value of the enum present in its description attribute to be…
Bruno Henri
  • 373
  • 1
  • 3
  • 15
0
votes
1 answer

C# JsonSerializer.Serialize>(numbers) will output a json with a list of 0's

using System; using System.Collections.Generic; using System.Text.Json; using System.IO; using System.Numerics; List numbers = new List(); numbers.Add(4); numbers.Add(3); File.WriteAllText("example.json",…
Travis Rivera
  • 428
  • 1
  • 4
  • 19
0
votes
0 answers

Issue with serializing 'object' with System.Text.Json

I need to store an unknown JSON structure from an external API, but when I serialize the data using System.Text.Json, the JSON output is incorrect. A working example can be found here: https://dotnetfiddle.net/k0zBAs Example data from external…
oli_taz
  • 197
  • 1
  • 4
  • 18
0
votes
1 answer

C# Polymorphic JSON deserialization for Dictionary/List objects

I need to deserialize dynamic JSON text that can represent either System.Collections.Generic.Dictionary or System.Collections.Generic.List< T>. I suppose I have to write custom converter but I'm not sure about how it should look like…
0
votes
1 answer

Deserialization with System.Text.Json in .NET Core 3.1 results in null property values

I have the following json: { "GameConfig":{ "TeamConstraint":{ "SameTeamPlayers":[ "Raghav", "Surya" ], "OppositeTeamPlayers":[ "Wolfman", "Pawan" ] }, "Players":[ "Tramp", …
Sai
  • 682
  • 2
  • 12
  • 35
0
votes
1 answer

System.Text.Json Serialization Behaviour

I have 3 classes; they contain each other in the following manner: TestClass1 - TestClass2 - TestClass3 - TestClass3 - TestClass2 - TestClass3 - TestClass3 What I'm trying to do is to serialize and then…
user12585721
0
votes
1 answer

How can I correctly skip an unknown property inside the JsonConverter.Read() method of System.Text.Json?

Using System.Text.Json, I am writing a custom JsonConverter.Read() deserialization method to deserialize a JSON object. The method reads each property name and value from the JSON and manually assigns the results into the deserialized object,…
dbc
  • 104,963
  • 20
  • 228
  • 340
0
votes
0 answers

System.Text.Json problem with complex interfaces

I have three classes: Hotel (implements IHotel) , Room (implements IRoom , which is inherited from IRoomDetails and IBookedRoom), ClientModel (implement IClientModel). public interface IRoomDetails { string Number { get; set; } …
Majestr32
  • 3
  • 1
0
votes
0 answers

Custom JSON Generic Type Serialization not working

I am using the new .NET serialization classes from System.Text.Json to deserialize a JSON response from a restful endpoint. The structure of the response is: public class RemoteCallResultDto { public bool Succeeded { get; set; } public…
arlvin
  • 379
  • 1
  • 4
  • 11
0
votes
1 answer

.NET 5 System.Text.Json configure [FromBody] to avoid deserialisation error with non-string dictionary key

I'm migrating a project from Microsoft.AspNetCore.Mvc.NewtonsoftJson to System.Text.Json. I couldn't do this in .NET Core 3.1 due to dotnet/runtime#38056 as some of my models contain properties of type IDictionary, something like: public…
Keith
  • 150,284
  • 78
  • 298
  • 434
0
votes
1 answer

System.Text.Json Serialize multiple objects/array

Could someone help me. I'm having problem serializing multiple elements. I'm getting this result which has multiple root elements. [ { "TITLE": "title1", "Total EP": 16, "Current EP": 1, "URL": "https://www...", } ] [ { …
mark123
  • 83
  • 1
  • 5
0
votes
1 answer

Forcing System.Text.Json to fail when deserializing to a model with an enum property which is absent from the json string

I'd like deserialization to fail for the following model: class ExampleModel { public ExampleEnum ExampleEnum { get; set; } public string ExampleString { get; set; } } enum ExampleEnum { Value1, Value2, } when the ExampleEnum's…
alexalok
  • 107
  • 2
  • 12
0
votes
0 answers

How can I get complete JSON string from Utf8JsonReader?

I'm working on custom JsonConverter (where T is base type of objects supported by this converter) and I need to implement public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) method. I have to read…
Kamil
  • 13,363
  • 24
  • 88
  • 183
0
votes
1 answer

System.Text.Json Custom Seriallization / Deserialization

I have the following class: public class PropoertyValue { string Id {get;set;} object Value {get;set;} string Type {get;set;} } When I serialize/deserialize Json I want the value property reflects the type specified in "Type" property. How can I…
Matteo Fioroni
  • 103
  • 2
  • 4
0
votes
1 answer

JObject.Parse in new System.Text.Json

I am trying to change Newtonsoft.Json.Linq to new System.Text.Json on my previous solution I use JObject.Parse(jsonstring) to convert a json string to a Json Object and return it to a OpenApi V3 UI With JObject.Pase I am able to transfor…
delucaezequiel
  • 483
  • 2
  • 9
  • 26