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
0 answers

System.Text.Json without knowing the response

I'm getting used to using System.Text.Json and I am wondering if there is a way to parse a JSON Response without knowing the fields that will come down. As an example the code I have to get an access token is as such: HttpWebRequest request =…
ConnorM
  • 9
  • 1
  • 7
0
votes
1 answer

System.Json.Net - deserializing a Task fails (no parameterless constructor)

I'm running into a problem where I can't deserialize a string into a Task using System.Text.Json (.Net 5). JsonSerializer.Deserialize>(serializedItem) Background I have a localized cache and store in it items retrieved from the DB. I…
DrGriff
  • 4,394
  • 9
  • 43
  • 92
0
votes
1 answer

System.Text.Json parse document that exists internal to a string

I receive string content that starts with a JSON value (could be simple or complex) and has some additional content afterward. I'd like to be able to parse the JSON document. I don't have control over the string, so I can't put any kind of…
gregsdennis
  • 7,218
  • 3
  • 38
  • 71
0
votes
1 answer

Issue returning a JSON associative array from an ASP.NET Core Web API

I have a Web API method in ASP.NET Core 3.1 that returns an enumerable list of objects: public async Task> Get() The Web API returns JSON by default. This has worked fine, until I added a property of type Dictionary
Jason
  • 319
  • 5
  • 15
0
votes
3 answers

extracting a value from a JSON string

I'm working on a Blazor application and I have a Json string from which I'm trying to extract a value. Json Data looks like this: {"a1":"a1234","e1":"e1234} I'm trying to extract the a1 value from this which is "a1234" My JSON Data is in a string…
Koosh
  • 876
  • 13
  • 26
0
votes
1 answer

System.Text.Json.JsonSerializer fails to deserialize the member

public class providerData { String rowId { get; set; } } public class providerPagedData { public int total { get; set; } public int totalPages { get; set; } public List items { get; set;…
0
votes
0 answers

Obtaining every single free-form property and its value, converting it into a raw, readable JSON payload

Say I want to output a JSON data structure to a requester. This JSON data would: Be free-form (Basically, it could be a value, object or even an array) Be returned to the frontend directly with no serialization (Frontend is a JS stack, returning…
Nicholas
  • 1,883
  • 21
  • 39
0
votes
1 answer

JsonDocument incomplete parsing with larger payloads

So basically, I have a HttpClient that attempts to obtain any form of JSON data from an endpoint. I previously utilized Newtonsoft.Json to achieve this easily but after migrating all of the functions to STJ, I started to notice improper…
Nicholas
  • 1,883
  • 21
  • 39
0
votes
0 answers

System.Text.Json.JsonSerializer.Deserialize returning object with all fields null in .Net Core 3.1

There seems to be a problem with System.Text.Json.JsonSerializer.Deserialize in .Net Core 3.1 This code: public class AuthAccessToken { [JsonProperty("access_token")] public string AccessToken { get; set; } [JsonProperty("expires_in")] …
0
votes
0 answers

Why does System.Text.Json.Serialization.JsonSerializer encode double-quotes instead of merely escaping them?

I am wracking my brain about this and can't figure out why or how to fix it. This test should pass: [Test] public void EncodingTest() { var json = JsonSerializer.Serialize("\""); Assert.AreEqual("\\\"", json); } but it doesn't. It's…
gregsdennis
  • 7,218
  • 3
  • 38
  • 71
0
votes
2 answers

system.text.json explicitly set null attributes while ignoring unset attributes when serializing

I am trying to serializing a POCO object into an update request. My unset values are serialized as null, which causes them to be updated to null. If I set IgnoreNullValues to true this fixes the problem. However, then there is no way to explicitly…
0
votes
1 answer

What is the path to the "System.Text.Json"?

I updated yesterday morning to the latest versions of Xamarin and Xcode. I am now posed with this error when loading the iOS project: "Failed to resolve assembly: 'System.Text.Json, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51".…
Marc George
  • 134
  • 1
  • 18
0
votes
2 answers

Unable to deserialize valid JSON into a class with generic IEnumerable property

I am currently struggling to deserialize received JSON into a DTO object which has IEnumerable data property. Using ASP.NET Core 3.1 and System.Text.Json 4.7.0. Below is displayed the JSON { "data": [ { "alternateId":…
ajr
  • 874
  • 2
  • 13
  • 29
0
votes
2 answers

C# - Can I set the type of a generic parameter at runtime to tidy up the following code?

I have a the following example classes public class Item where TMessageType : ItemMessage { public int Prop1 { get; set; } public string Prop2 { get; set; } public int MessageType { get; set; } public TMessageType…
Killian
  • 414
  • 2
  • 10
0
votes
0 answers

Find stream positions of JSON fragments

I am trying to find stream start and stop positions of JSON fragments. At the moment I am using JsonTextReader which allows me to use the JsonTextReader.Path property which can be checked using a regex for matching. It does have LinePosition and…
Bent Rasmussen
  • 5,538
  • 9
  • 44
  • 63