Questions tagged [system.text.json]
System.Text.Json is the built-in JSON facilities added in .NET Core 3.0.
system.text.json
1,170
questions
1
vote
0
answers
22
views
How to parse JSON with references in a .NET Native AOT project?
Deserializing JSON files using System.Text.Json in a Native AOT project requires the source generation API, which takes a JsonSerializerContext object. I've managed that.
Now it appears that the JSON ...
-1
votes
1
answer
44
views
How do I query System.Text.Json.Nodes.JsonArray by value in .net core c#
I wanna query an System.Text.Json.Nodes.JsonArray by prop value ,
Is there any JsonArray function can query JsonObject in which array index without foreach/forloop or extra libray ?
[
{"...
0
votes
0
answers
28
views
How to read `DeclaringType` from `JsonPropertyTypeInfo` in System.Text.Json?
I want to customize serialization based on the type of the property. To do that I would like to read DeclaringType from JsonPropertyInfo. This is an example from Microsoft documentation on how to ...
1
vote
0
answers
67
views
do not serialize empty collections (and handle accordingly in deserialization)
I have a bunch of POCOs that can be (de-)serialized from/to json. A lot of content is collections. I want the serialized JSON to only contain a specific property if its collection is not empty (...
0
votes
2
answers
53
views
Problem with Serializing JSON to CamelCase in C#
I am trying to serialize a JSON string to convert property names to camelCase using the System.Text.Json library. However, I still get the outcome with PascalCase.
Here is my code:
var stringJson = &...
0
votes
0
answers
57
views
Serializer not returning expected output in .NET Core
I have a controller which returns Task<ActionResult> which internally returns a List<CustomObjectA>.
The structure of CustomObjectA is like this:
[DataContract]
public class CustomObjectA
{...
0
votes
0
answers
25
views
Source Generator not running when using System.Text.Json.JsonSerializer
I have a large list of types that I need to have basic CRUD services and editors for. I intend to use Source Generators to create all of these classes at compile time based on a json file containing ...
1
vote
0
answers
39
views
How to resolve the generic form of a JsonConverter in System.Text.Json
I know that this issue is more a question of the limitations of C# generics than it is a question about .NET Core (8.0) JSON Serialization but it is driving me crazy.
When getting 'underneath the hood'...
1
vote
1
answer
56
views
From a minimal ASP.NET Core Web API how do I return a JObject while maintaining the nested elements?
I am building a minimal ASP.NET Core Web API. One of my endpoints needs to return data contained in a JObject. This JObject represents a complex nested data structure. What I am finding is that the ...
0
votes
0
answers
29
views
System.Text.Json ecapes single quotes by design [duplicate]
I know that System.Text.Json escapes single quotes by design, but the examples for how to allow certain characters to not be escaped from MS Docs doesn't work for me as I want to keep single quotes in ...
0
votes
1
answer
68
views
Why is using JsonSerializer.DeserializeAsyncEnumerable to deserialize a 1GB file resulting in 2GB+ memory allocation?
I need to deserialize a 1GB json file one element at a time in a streaming fashion and after doing some reading found JsonSerializer.DeserializeAsyncEnumerable to enable this while also keeping the ...
2
votes
1
answer
73
views
Enforce the use of Utf8JsonReader.ValueSequence for test purposes
I wrote my own BigIntegerConverter for JSON serialization/deserialization (.Net System.Text.Json)
In the Read method I checked if ValueSequence is used
...
string stringValue;
if (reader....
0
votes
0
answers
67
views
In C#, why does System.Text.Json.JsonSerializer.Serialize fail to serialize correctly when using dependency injection (interfaces)? [duplicate]
Why does the following write out only "{}"?
var myLogin = new TestLogin
{
UserName = "[email protected]",
Password = "Pass123"
};
Console.WriteLine(System.Text.Json....
0
votes
0
answers
43
views
Ban entire namespace with BannedApiAnalyzers
I am trying to ban the usage of Newtonsoft.Json package in my codebase, and I am trying to use the BannedApiAnalyzers Nuget package (latest stable version, 3.3.4).
My problem is that while I am able ...
0
votes
1
answer
39
views
Trying to deserialise and the JSON value could not be converted to class(?)
very newbie programmer here trying to learn C#. I'm trying to deserialise a JSON file and then print the values inside. However, I'm met with a Jsonexception in the form of cannot be converted to the ...