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

Deserializing a JSON with nested dynamic property names

I'm trying to deserialize a pretty ugly JSON provided by an external REST API and am wondering about the "proper" way to do that (I'm using System.Text.Json in .net 6). Details follow: I have a model for the data: class DeviceData{ //lots of…
-2
votes
2 answers

convert json to c# object

My c# model public class Student { public string id{get;set;} [System.Text.Json.Serialization.JsonPropertyName("ref")] public int @ref{get;set;} } My ASP.Net Core API method [HttpPost] public async Task Get([FromBody] Student…
MARKAND Bhatt
  • 2,428
  • 10
  • 47
  • 80
-2
votes
1 answer

Indexing JsonElement Array

Dear Community Members Despite online searches, it is wondered how to efficiently index and retrieve corresponding values of a JsonElement Array using C#: string srep2 = " [ " + srep + " ] "; using JsonDocument doc = JsonDocument.Parse(srep2); …
dark.vador
  • 619
  • 1
  • 6
  • 25
-2
votes
1 answer

How to correctly parse JSON with nested arrays in C#

I have following JSON file: [ {"sport": "CYCLING_SPORT"}, {"source": "TRACK_MOBILE"}, {"created_date": "2016-03-28 12:00:00.0"}, {"start_time": "2016-03-28 12:00:00.0"}, {"end_time": "2016-03-28 13:00:00.0"}, {"duration_s":…
serwus
  • 155
  • 1
  • 14
-2
votes
1 answer

How to format a JSON object within RestSharp

I am using RestSharp to make a POST call to an external API. I am adding the payload via: request.AddParameter({field_name}, {field_value}) The API accepts { "name": "value" } (correct json format) but does NOT accept { name: "value" } If you…
Angel
  • 543
  • 5
  • 13
-3
votes
1 answer

How to customize System.Text.Json serialization of certain fields?

I need to (de)serialize objects which reference 3rd party API objects which arent serializable. However I dont need their content to be serialized. I just want to serialize Id of these objects and then retrieve them on deserailization. Short…
Boppity Bop
  • 9,613
  • 13
  • 72
  • 151
-3
votes
1 answer

System Text json deserialize string with escaped character

I've got the string value : var jsonStringValue= "[{\"id\": \"001\",\"schoolName\": \"Johnson Primary School\",\"rules\":…
Carrie Kaski
  • 133
  • 7
-3
votes
1 answer

C# deserializes into 0/null?

I'm trying to learn deserialization and I have it semi-working, but when I try to deserialize an int, it returns 0 or null (no null errors just outputs 0). public partial class Form1 : Form { public string basicjson = Application.StartupPath +…
TheTripleDeuce
  • 103
  • 1
  • 1
  • 7
-3
votes
3 answers

System.Text.Json - How do I sort JsonArray using OrderBy?

I am using System.Text.Json and right now, I'm trying to figure out how to sort a JsonArray without deserializing it, if that is at all possible. I have been able go get other LINQ functions to work with JsonArrays, however, I cannot seem to get…
NateLFO
  • 9
  • 2
-3
votes
1 answer

How to convert a string to an object in C# .NET Core?

I want to use System.Text.Json instead of Newtonsoft.Json. But, I was unable to convert the string to an object. Here is my request: {"Abc":'{"Property1":"abds","property2":"232"}'} I've tried to parse this string by…
prasanthi
  • 562
  • 1
  • 9
  • 25
-3
votes
1 answer

Deserialize property to different class based on other property c#

I know there are many similar questions on SO, however all the ones I've found require a shared base class in order to work. With a stream of JSON data like this: [ { "webhookType": "order", "data": { "id": "eeiefj393", …
Alasdair
  • 19
  • 4
-5
votes
0 answers

Is System.Text.Json that slow or am I missing something?

I'm using the .NET Framework 4.7.2. Stopwatch sw = new Stopwatch(); sw.Start(); JsonDocument jdoc = JsonDocument.Parse("{\"a\":123456789}"); JsonElement test = jdoc.RootElement.GetProperty("a"); sw.Stop(); Console.WriteLine(test + $"…
killaz
  • 37
  • 1
  • 8
1 2 3
64
65