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

Streaming JSON using the dotnet Core 3 System.Text.Json Api

I'm developing a WPF web client using dotnet Core 3.x, and I'm utilising the System.Text.Json APIs. I am trying to use a Stream to pass the data between objects to minimise peak memory usage, as some large messages are being sent. The wrapper…
David G
  • 172
  • 2
  • 10
0
votes
2 answers

what are the extended features using System.Text.Json(.netcore-3.0) instead of Newtonsoft.Json?

I have used Newtonsoft.Json for converting JSON object to string and vice versa. Recently I read about System.Text.Json in https://learn.microsoft.com/en-gb/dotnet/api/system.text.json?view=netcore-3.0. I read the article and it is faster than…
Jayakumar Thangavel
  • 1,884
  • 1
  • 22
  • 29
0
votes
0 answers

How can I achieve this blacklisting of properties based on Property Type with Utf8Json?

Goal Based on a Type and string representing the parent class and property respectively, I want to filter properties on serialization. I'm aware that Utf8Json (and Newtonsoft for that matter) support attributes on the field but due to the codebase…
Geesh_SO
  • 2,156
  • 5
  • 31
  • 58
0
votes
0 answers

Could JsonDocument be used as ContractResolver?

I have a question regarding the newly released .NET Core 3.0 and its new System.Text.Json, I would like to ask if the new JsonDocument could be used similarly to ContractResolver class in Newtonsoft JSON.NET. What I need is quite straightforward,…
AltairMS
  • 1
  • 2
0
votes
1 answer

Azure Function v2 and system.text.json

I am trying to implement a function that uses .net core 3 (preview 9) as a target framework and uses the new System.text.json namespace. Here is my code: using System; using Microsoft.Azure.WebJobs; using Microsoft.Azure.WebJobs.Host; using…
Liam
  • 5,033
  • 2
  • 30
  • 39
0
votes
1 answer

JsonIgnore and non-supported collection objects

It seems that the System.Text.Json serializer doesn't take into account JsonIgnore attributes when executing - I get this exception: System.NotSupportedException: 'The collection type…
Liam
  • 5,033
  • 2
  • 30
  • 39
-1
votes
2 answers

Upgrading from .net5 to .net7 Json Serialization stopped working

We had an ASP.NET Core 5 Web API backend alongside a ReactJS UI app. In startup we instantiated the json framework the following way: services.AddControllers() .AddNewtonsoftJson() .AddJsonOptions(options => { …
Lucas
  • 1
  • 3
-1
votes
1 answer

System.Text.Json Deserialize dictionary with JsonExtensionData attribute

I'm serializing/deserializing a dictionary, but when I deserialize, instead of the values being objects, they are JsonElements. I have a unit test that demonstrates the problem. How can I deserialize these values to objects? Can…
Vic F
  • 1,143
  • 1
  • 11
  • 26
-1
votes
2 answers

populate list from values in string

I have a string like so: string newList = "{"data":[{"ours":176,"theirs":"TAMPA","companyId":111},{"ours":176,"theirs":"ORLANDO","companyId":111}]}" How can I extract the contents into a list allValues = new list()? so: public…
John
  • 3,965
  • 21
  • 77
  • 163
-1
votes
1 answer

Custom deserialize from JSON navigating the response

I have a API that returns a JSON like the one below and I have to deserialize it in a C# object: { "found": true, "resultsData": [ { "2023-05-13": [ { "info1": "Test", …
pinguinone
  • 433
  • 1
  • 6
  • 14
-1
votes
2 answers

How to serialize IEnumerable like a dictionary using System.Text.Json

Using .NET 6, System.Text.Json namespace to serialize some classes. I'm trying to serialize some models from a database (represented as classes in C#) as JSON in a REST API. The models have one property that is the primary key in the database, for…
Joqsun
  • 9
  • 1
-1
votes
2 answers

How can I parse a JSON into a dynamic object allowing access to fields via dot notation using System.Text.Json?

I'm implementing a feature where a user can write an arbitrary expression that needs to be evaluated against some context. Users should be able to write expressions referring to a dynamic JSON payload. I'm using Roslyn CSharpScript to execute the…
Jorgoth
  • 9
  • 2
-1
votes
2 answers

(De)Serializing type with interface-based polymorphic properties into/from JSON

First of all, I apologize for the length of below code; it's about as minimal as I could get it. I'm trying to (de)serialize a dozen or so messages that are defined in a 3rd party library; I cannot modify these classes and interfaces in any way. The…
RobIII
  • 8,488
  • 2
  • 43
  • 93
-1
votes
1 answer

Automapper exception when mapping JsonObject in .Net6 - "The node already has a parent"

I'm trying to map a JsonObject (System.Text.Json) with AutoMapper 12.0.0 Source: public record Request { public Guid RequestId { get; set; } public JsonObject AdditionalParameters { get; set; } } Destination: public record…
-1
votes
4 answers

How to deserialize an anonymous object using C# System.Text.Json and access its properties?

I have the following code: var model = new { Name = "Alexander" }; var serializedModel = JsonSerializer.Serialize(model); var deserializedModel = JsonSerializer.Deserialize(serializedModel); var name =…
user113000
  • 17
  • 7