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

How to serialize object in ASP.NET Core/6 using a camelCase?

When using ASP.NET Core/6 to return object as JSON we use return Ok(data) which takes the data object and serialize it using camelCase. But, what I want to serialize an object manually, it does not serialize using camelCase. Here is how I am…
Jay
  • 1,168
  • 13
  • 41
0
votes
0 answers

How to virtually add Json attribute to an existing class [c#, system.text.json]

How to "virtually" add Json attribute to an existing class? or more precisly How is it posible to change the serialize behavior for a single property w/o creating a converter for the whole class and w/o rewriting/wrap the the whole class? If it…
Kux
  • 1,362
  • 1
  • 16
  • 31
0
votes
2 answers

JsonConverter - WebApi - Case Sensitivity - Polymorphic

I'm using a JsonConverter to deal with a polymorphic collection: class ItemBatch { List Items { get; set; } } // For type discrimination of ItemBase class ItemTypes { public int Value { get; set;…
Neil W
  • 7,670
  • 3
  • 28
  • 41
0
votes
0 answers

Deserialization returns null properties (JsonSerializer)

I know there is a lot of questions about this on SO but I still can't figure why this deserialization is not working. Maybe one more pair of eyes helps me with this. I have this DTOs: public class BasicDTO { public OperatorEnum Operator…
Weenhallo
  • 324
  • 2
  • 8
0
votes
1 answer

How to retrieve the Id of a newly Posted entity using ASP.Net Core?

I Post a new Waste entity using the following code: var result = await httpClient.PostAsJsonAsync(wasteApiRoute, waste); The Api Controller (using the code created by VS) seems to try to make life easy for me by sending back the new Id of the Waste…
Dabblernl
  • 15,831
  • 18
  • 96
  • 148
0
votes
1 answer

Deserializing array of [price, quantity]

Here is the endpoint I'm trying to deserialize. The issue is within the bids, asks and changes. How do I handle it? The API says it's array of [price, quantity]. Snippet [JsonNumberHandling(JsonNumberHandling.AllowReadingFromString)] public record…
nop
  • 4,711
  • 6
  • 32
  • 93
0
votes
1 answer

How to write an attribute for replacing sensitive data on serialization using System.Text.Json

I am logging my parameter models on console. In there I don't want to display the user password on login/register raw in logs, I want *. My limitation is that I need to use System.Text.Json! This is what I…
Wasyster
  • 2,279
  • 4
  • 26
  • 58
0
votes
1 answer

How to create a JSON body with PowerShell which is Deserializable by .NET6 when using az rest to call a .NET6 Azure Function

We are using AzureCLI to be able to call an Azure Function endpoint upon a successful deployment. The call to get token works and the call to our azure function makes it into MyFunction. The problem is the format of the body when it arrives. If we…
0
votes
0 answers

Custom EnumConverter not returning default enum

Having a custom EnumConverter that should return the default enum isn't working as I expect. Enum : public enum MyEnum { Unknonw = 0, FirstEnum = 1, SecondEnum = 2 } The converter : public override ContractType Read(ref Utf8JsonReader…
user7849697
  • 503
  • 1
  • 8
  • 19
0
votes
2 answers

Read in Byte value and convert to Null

I am trying to write a function that handles empty values for the datatype Byte. The reader is reading in a JSON string and serializing to my models. One of the models has a Byte property. If the reader encounters a blank or empty string for a Byte,…
SkyeBoniwell
  • 6,345
  • 12
  • 81
  • 185
0
votes
1 answer

Can't serialize GeoJson coordinates in .Net Core controller

I have a .net 6 API project that exports FeatureCollections. I'm using 'NetTopologySuite.IO.GeoJSON' version 2.0.4, and have a public API call like: public async Task ExportGeoJSON() { GeoJSON.Net.Feature.FeatureCollection ret =…
Phil
  • 1,852
  • 2
  • 28
  • 55
0
votes
2 answers

Deserialize json properties when property name matches only partially JsonPropertyNameAttribute.Name value

I am looking for a mechanism in the System.Text.Json package, where I would be able to deserialize JSON on partially matching property names. Unfortunately, the API that I am writing a client for responds with different property names depending on…
phoenix
  • 365
  • 1
  • 4
  • 15
0
votes
0 answers

System.Text.Json unable to deserialize doubles properly without being affected by the culture

I have a problem that I checked some time ago and also posted on Microsoft Github since it seemed a bug, I'm speaking of years ago. I was checking if was solved but it seems no. It is a trivial thing: I'm using Google Maps APIs with an autocomplete…
ollie10
  • 317
  • 2
  • 11
0
votes
2 answers

Deserialize Json string with child objects

Got the following structure given: public class TaskList { public string Name { get; set; } public List ToDoTasks { get; set; } } public class ToDoTask { public string Name { get; set; } public string Note { get; set; } …
Seraphim
  • 37
  • 7
0
votes
0 answers

System.Text.Json source generation not working

I'm trying to add System.Text.Json source generation to one of my projects, a .net6 rest api. When I try to specify the partial class according to instructions I get this behavior: vs thinks this won't build properly But I can still build the…