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

System.Text.Json - Return a list of base class from controller with all derived class properties

In a new .NET 5 project, I have a List as a property on a ViewModel. It has 4 properties on it. At runtime, I populate that list with 4 different derived classes, each with about 3 distinct properties of their own, in addition to the…
Jonesopolis
  • 25,034
  • 12
  • 68
  • 112
0
votes
1 answer

How to serialize to the given TextWriter instance using System.Text.Json?

I know how to serialize to a Stream, but is it possible to serialize to a TextWriter? The problem is that TextWriter does not expose a Stream object. It seems there is no such option, but maybe I am missing something. EDIT 1 Please, allow me to…
mark
  • 59,016
  • 79
  • 296
  • 580
0
votes
2 answers

How to deserialize a property of a child JSON object to a property in the parent model using System.Text.Json?

First off, I had a hard time with the title of this one; I'll edit it if I get any better suggestions. I have a json string that looks like this { "chapters": [ { "id": 0, "tags": { "title": "Chapter 1" …
master_ruko
  • 629
  • 1
  • 4
  • 22
0
votes
1 answer

Mixing System.Text.Json and Newtonsoft.Json with Swagger

One of my company's applications import packages that contain models that become responses from our API using Newtonsoft.Json; public class Foo { [JsonProperty("bar"] public string Bar { get; set;} } We have for our own models migrated to…
Florin
  • 1
  • 1
0
votes
0 answers

Is there a similar approach to CustomCreationConverter in System.Text.Json?

I have used CustomCreationConverter in Newtonsoft.Json for many years. Nowadays, I am trying to migrate to System.Text.Json. Is there a similar approach? I just want to add something in the method "Create".
Pop Young
  • 11
  • 3
0
votes
0 answers

How to Json ignore string property when its assigned specific string value c#

public string Name{ get; set; } Hi Team, I'm new to json ignore thing. I went through lot of other solutions for ignore my string property from json. but the thing was, Custom converter is not practical for to my code, because it has lot of…
Harendrra
  • 107
  • 1
  • 10
0
votes
1 answer

how to set ignore null value when using system.text.json

in the previous asp.net framework, we can use nullvaluehandling (json.net) to ignore the null JSON value. but now in asp.net core, it's starting using system.text.json. how can I set null value handling using this library? thanks
10120
  • 95
  • 8
0
votes
1 answer

System.Text.Json - Polymorphic serialization for property is not working

KrakenSubscribeRequest.Details is expected to be polymorphic, but it isn't and the interval property is left behind. If KrakenSubscribeRequest was polymorphic, it would've worked with the code below, but in this case KrakenSubscribeRequest.Details…
nop
  • 4,711
  • 6
  • 32
  • 93
0
votes
0 answers

System.Text.Json - Unable to find TokenType Integer, Float, etc

I'm trying to migrate the following Json.NET DateTimeConverter to System.Text.Json. The issue is that I cannot find JsonTokenType.Integer or JsonTokenType.Float. There is only JsonTokenType.Number. System.Text.Json public sealed class…
nop
  • 4,711
  • 6
  • 32
  • 93
0
votes
1 answer

Deserializing an array with System.Text.Json

It is possible to deserialize an array with Json.NET. How can I deserialize the following JSON using…
nop
  • 4,711
  • 6
  • 32
  • 93
0
votes
0 answers

How to deserialize immutable types from standard library using System.Text.Json?

I am trying to serialize and deserialize System.Diagnostics.ActivityContext struct. According to documentation How to use immutable types and non-public accessors with System.Text.Json I need to add [JsonConstructor] attribute to struct constructor,…
Algirdas
  • 1
  • 2
0
votes
0 answers

Unable to deserialize a readonly struct using System.Text.Json

Pretty straightforward question. Here is a minimal reproducible example which fails to deserialize Side, which is a readonly struct. I want to keep it struct. I know it's possible to make it work with an enum. The JSON value could not be converted…
nop
  • 4,711
  • 6
  • 32
  • 93
0
votes
1 answer

System.Text.Json unable to convert a property which is a struct

System.Text.Json.JsonException: The JSON value could not be converted to Models.Side. Path: $.S | LineNumber: 0 | BytePositionInLine: 107. JSON { "stream": "c3uwBXY4P4eHD2HNkk5Tmj9SzXKZHRfxMpiWrQsXkvICePRWecoN5gFInj6O", "data": { …
nop
  • 4,711
  • 6
  • 32
  • 93
0
votes
1 answer

c# json search for string when I have unknown property

I would like to search my json in c# for string, but the structure of the json is dynamic to me, and the property name is dynamic, this is the example of my json file: [ {"Bluebook": {"Chapter8": {"Verse10":"This is some sentence"} } } , {"A…
0
votes
1 answer

System.Text.JSON 6.0.2 version and above throw error with JsonSerializer.Deserialize

I have created a basic template Class library (see image below) and added just one reference system.text.json (version 6.0.2) through manage nuggets Created a Console application with the above Class library as reference. (basic template just…
MeeGee
  • 25
  • 1
  • 7