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

How to force a particular property to be deserialized as string instead of number?

I have different backends giving back almost the same JSON data model except for a nested json object with the id field which sometimes can be a pure number such as: { "something": { "id": 1 } } or a string, such as: { "something": { "id":…
Eugene
  • 217
  • 8
  • 24
0
votes
1 answer

The JSON value could not be converted to Scraper.items[]

so I am trying to convert a JSON string to a list of objects that I made myself but for some reasons it keeps throwing me errors and after googling it I couldn't find my error. Here is what throws the error. (I already tried using a list instead of…
D.7
  • 3
  • 2
0
votes
2 answers

Cannot Deserialize Nested JSON in C#

I am new to programming and to C#. I'm using Visual Studio (latest) to write my app. This is a console app that is attempting to read a log (text) file where each line is a separate JSON entry. This is what a single item JSON entry looks like: { …
jchornsey
  • 365
  • 1
  • 4
  • 10
0
votes
2 answers

.Net System.Text.Json: how to deserialize to a class constructor where parameters nullability doesn't match class properties nullability

I have a bunch of Json files that I want to deserialize to immutable classes. E.g. a Json file like this : { "Prop1": 5, "Prop3": { "NestedProp1": "something", "NestedProp3": 42 } } Should be deserialized to classes like that: public…
Manuel Ornato
  • 19
  • 1
  • 3
0
votes
1 answer

How to remove a middle property from JSON in System.Text.Json?

Let's say we have these C# classes: public class Teacher { public long Id { get; set; } public string Name { get; set; } public boolean IsActive { get; set; } public dynamic RelatedItems { get; set; } } public class Student { …
Hossein Fallah
  • 1,859
  • 2
  • 18
  • 44
0
votes
1 answer

Problem during serialization with UNICODE char with System.Text.Json

I have a problem during the serialization with data modified during deserialization (i dont think its the problem ) some \u char are not correctly transformed...and i dont see how to fix that.. even with a global encoder.... See my comments about…
Frenchy
  • 16,386
  • 3
  • 16
  • 39
0
votes
1 answer

How to serialize a generic object in System.Text.Json (migrating from Newtonsoft)?

Apologies if this has been asked before, but I couldn't quite find the relevant question. I am using Newtonsoft to serialize a type like this: class MyClass { object Val { get; set; } } The Val property is set/given to me from another assembly,…
pushkin
  • 9,575
  • 15
  • 51
  • 95
0
votes
1 answer

How to serialize a TimeSpan as "HH:mm:ss" with System.Text.Json.JsonSerializer

I need to serialize an object which has a TimeSpan property, and I need that property to be serialized as "HH:mm:ss". Instead, I get the…
thyago
  • 31
  • 7
0
votes
0 answers

How to copy Stream property straight to response body on JSON serialization

I want to optimize response returning from ASP.NET Core application. In order to do that I'm serializing the object to JSON UTF-8 bytes and inserting it to SQL as varbinary(max). I initially though that I'll get a stream from the column value using…
roten
  • 196
  • 13
0
votes
1 answer

json is parsed as null

I have a json structure like below. {"data":{"accountType":"New"}} The model for this is as follows. public class Data { public string accountType { get; set; } } Below is how I am parsing this data using System.Text.Json. string json2 =…
whoami
  • 1,689
  • 3
  • 22
  • 45
0
votes
1 answer

Select type to use for deserialization in System.Text.Json

I have a .NET 6 app that needs to deserialize some JSON data to C# objects, using System.Text.Json. However, in the classes I'm trying to deserialize I have a classic case where a property has a base-class type, like this: public class…
Master_T
  • 7,232
  • 11
  • 72
  • 144
0
votes
1 answer

System.Text.json JsonSerializer unicode issue on read from json file

In an C# .net core environment, using the System.Text.Json unicode characters are substituted. For example "ü" is shown after reading the json file into a list of an object into another symbol Passwort zurücksetzen becomes Passwort zur�cksetzen I…
0
votes
0 answers

Reduce size of JSON produced by System.Text.Json

I am building a web app using Blazor WASM with a .NET backend. We are hitting a problem, where the json returned from the API is bigger than we want/need it to be. Maybe the right solution is to write custom serializer methods for each action on the…
Joao Leal
  • 5,533
  • 1
  • 13
  • 23
0
votes
1 answer

JsonSerializer.Deserialize won't work in class C#

I am trying everything I can but the object is not getting deserialized, I tried almost all the possible solutions to the problem but nothing is working, if someone can help that would be great. please see below is the code snippet for the code it…
Russian Federation
  • 194
  • 1
  • 5
  • 24
0
votes
1 answer

How to map a Json duration with this format "PT0.123875S"

I'm receiving a json object with a field duration like this "duration":"PT0.123875S", With System.Text.Json what type is supposed to receive this ? I was expected TimeSpan but it does not work.
JuChom
  • 5,717
  • 5
  • 45
  • 78