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
-1
votes
1 answer

Serializing and Deserializing stream using system.text.json

I am new to using System.Text.Json. I was using BinaryFormatter, now need to migrate to System.Text.Json due to Security vulnerabilities Binaryformmater poses. I need to serialize the object into the stream and store it in disk. Then Upon calling…
Al Pa chino
  • 75
  • 2
  • 8
-1
votes
1 answer

Parse json and get values using System.Text.Json

I have very large json file with lots of data. Structure looks like this { "country": "AD", "name": "Pas de la Casa", "lat": "42.54277", "lng": "1.73361" }, In my current c# code I have coordinates, let's say var lat =…
10101
  • 2,232
  • 3
  • 26
  • 66
-1
votes
1 answer

.Net Core 5 System.Text.Json CamelCase is not applied by default

According to https://learn.microsoft.com/en-us/aspnet/core/web-api/advanced/formatting?view=aspnetcore-5.0 CamelCase should be the default formatting for System.Text.Json. I am however getting PascalCase i.e. first char is a capital. I tried…
KeithT
  • 1
  • 1
-1
votes
2 answers

How to Serialize abstract class in System.Text.Json

I have the following class public abstract class Settings { private string _filename; protected virtual void defaults() { } public static T Load(string filename) where T :…
-1
votes
1 answer

Newtonsoft.json or System.Text.Json Serialize only the property's defined type not inherited values

Consider you have: class ContentRef { SomeProperty } class Content : ContentRef { SomeOtherProperty } class C { ContentRef someProperty; List someList; } var someObject = new C { someProperty = new Content(), someList =…
James Hancock
  • 3,348
  • 5
  • 34
  • 59
-1
votes
1 answer

How to include description in JSON file using Dictionary C#

I'm starting using C# and have a lot to learn. I'm trying to create a JSON file with a dictionary (thats easy). JsonSerializer.Serialize(MyDictionary) But it returns the data without descriptions... { "-0255504", "1" …
-1
votes
1 answer

Deserialize a JSON Object in C# from a string with multiple objects

I've been trying to deserialize a JSON file coming from a webpage, then putting it into a list. The code is as follows: public async Task Update() { try{ HttpResponseMessage response = await…
xtremethegamer
  • 59
  • 1
  • 2
  • 6
-1
votes
2 answers

How to Deserialise JsonDocument To POCO Using System.Text.Json

Using HttpClient I post a json document to my controller. public async Task PostAsync(string url, T doc) { var json = JsonConvert.SerializeObject(doc); var response = await mHttp.PostAsync(url, new…
Paul Stanley
  • 1,999
  • 1
  • 22
  • 60
-1
votes
1 answer

JsonConverter Array syntax to Dictionary

I have an dictionary that is serialized as an array of arrays: "values":[["key1",0], ["key2", 0]] My goal is to deserialize it to Dictionary, eventually List> using an JsonConverterAttribute from…
SzejkM8
  • 9
  • 1
  • 1
-1
votes
1 answer

json will not be be deserialized to an appropriate model?

I have this json [ { "internalName": "a" } ] And a model public class UC { public string InternalName { get; set; } } which was generated from QuickType but I cannot seem to deserialize this…
kafka
  • 573
  • 1
  • 11
  • 28
-1
votes
1 answer

Remove white spaces from json after loading it from file using System.Text.Json in .net core 3.1

I am using .NET Core 3.1 with System.Text.Json I am reading JSON from file var jsonFilename = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "WellKnownConfig.json"); if (System.IO.File.Exists(jsonFilename)) { var…
Kamran Shahid
  • 3,954
  • 5
  • 48
  • 93
-2
votes
1 answer

json Deserialize dynamic to convert it to model

I'm trying to convert dynamic AdvanceEvent = JsonSerializer.Deserialize(File); to model class that is AdvanceEventsDto public class AdvanceEventsDto { /// /// The Event List ///
-2
votes
1 answer

How to get JSON response same as the property name?

I have my Response model class below. using System.Text.Json.Serialization; public class Response { [JsonPropertyName("PFUserID")] public string UserId { get; set; } } I am using JsonSerializer.Deserialize(jsonHelperResponse); to…
tRuEsAtM
  • 3,517
  • 6
  • 43
  • 83
-2
votes
1 answer

convert JSON to c# dictionary

I have a .json file which I want to convert to a c# dictionary (string, string). the JSON looks like: [ { "data": "data", "id": "1" }, { "data": "data2", "id": "2" } ] what is the simplest way to…
Shax
  • 7
  • 1
-2
votes
1 answer

c# system.text.json deserialize "different" object to an array of one class

I've a json that have objects like this "SeasonalInfoBySeasonID": { "aa8e0d2d-d29d-4c03-84f0-b0bda96a9fe1": { "ID": "aa8e0d2d-d29d-4c03-84f0-b0bda96a9fe1", "A": "1", "B": 5, …
Dartz
  • 11
  • 4
1 2 3
64
65