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

Parse heterogeneous JSON objects

I send JSON objects from a client to a server. In the server I need to do some action based on the object type. I could send a filed type in every request then try to parse JSON against base Message class: public class Message { string type {…
user2146414
  • 840
  • 11
  • 29
0
votes
1 answer

How to deserialize quoted nested object using System.Text.Json in .Net 5

I got this two classes public class RootObj { public int a { get; set; } public SubObj sub { get; set; } } public class SubObj { public int b { get; set; } } The JSON string to be deserialized is like { "a": 1, "sub":…
Jiruffe
  • 47
  • 5
0
votes
0 answers

JsonConverter - Nices way to implement default "Write"

Since the currect version of the System.Text.Json Serializer does not support inherited properties on interfaces I'm looking for the neatest way to mock it's behavior in the Write method. Right now I'm calling the Serialize method, e.g. public…
tris
  • 863
  • 4
  • 9
  • 22
0
votes
1 answer

Parse a JSON nested array with numbers and strings

I receive the following JSON response from a web server: [ [ 1499040000000, "0.01634790", "0.80000000", "0.01575800", "0.01577100", "148976.11427815", 1499644799999, "2434.19055334", 308, "1756.87402397", …
0
votes
0 answers

Deserialization of stream using System.Text in .net core

I have a dumb question, but I dont know how to solve it. List currencies = new List(); var responseStream = await response.Content.ReadAsStreamAsync(); currencies = await JsonSerializer.DeserializeAsync(responseStream,…
Stefan0309
  • 1,602
  • 5
  • 23
  • 61
0
votes
1 answer

remove cycle reference from Web API Asp.Net Core 5

I want to remove cycle object reference of my API controllers, by setting the serialization MaxDepth. I used the following code in startup.cs but it has no effect : services.AddControllers().AddJsonOptions(o => new…
nAviD
  • 2,784
  • 1
  • 33
  • 54
0
votes
2 answers

System.Text.Json deserializing where there is two possible property names

Is it possible to deserialize a JSON into a class where a property name could be one of two values? For example both of these JSONs would deserialize into the same property: var json1 = "{\"A\":5}"; var json2 = "{\"B\":5}"; I…
flux
  • 1,518
  • 1
  • 17
  • 31
0
votes
2 answers

Serialization/deserialization of json text with mix casing for property names using C# System.Text.Json

I am trying to serialize/deseralize a vendor json file that contains both camel case and pascal case property names. The resulting objects use Pascal case for its properties. What's the proper way of dealing with this situation using…
Rushui Guan
  • 3,023
  • 1
  • 24
  • 26
0
votes
1 answer

How to deserialize nested timespan property with System.Text.Json?

I am trying to deserialize json data with System.Text.Json utilizing converters. The raw content of the http response shows that the json contains valid data The converter to deserialize the content into the type specified observable collection is…
Marcus Runge
  • 635
  • 6
  • 17
0
votes
1 answer

System.Text.Json Deserialize and get Property Values

I'm struggling to understand how to access the property values from a class which was derived by using the Visual Studio 'Paste Special' into a new C# Model. The JSON was copied from an API returning log events, in the example I've only included one…
OJB1
  • 2,245
  • 5
  • 31
  • 63
0
votes
1 answer

Unable to Deserialize DateTime, Guid, or Enum with System.Text.Json

I filed a bug, but this seems like such a basic fundamental scenario that I must be missing something: Bug: https://github.com/dotnet/runtime/issues/48202 I am unable to Deserialize DateTime, Guid, or Enum with System.Text.Json. Here is a very…
Matt Sanders
  • 953
  • 1
  • 13
  • 23
0
votes
1 answer

How do I append an JsonProperty to another JsonProperty

I have this JsonDocument which looks like this string jsonString = "{\"year\": 0, \"class\": [], \"schools\": []}"; JsonDocument newSchema = JsonDocument.Parse(jsonString) And a bunch of JSON files, with these properties filed out. Each of the JSON…
I am not Fat
  • 283
  • 11
  • 36
0
votes
0 answers

ASP.NET Core serialization results in empty object

I have an object defined as such public class FilingSearchCriteria { public int? FilerId { get; set; } public int? TypeId { get; set; } public DateTime? StartDate { get; set; } public DateTime? EndDate { get; set; } public bool?…
americanslon
  • 4,048
  • 4
  • 32
  • 57
0
votes
0 answers

C# Adding extension methods for JsonConverter

I've got several JsonConverters and want to refactor some common validation code out into a set of extension methods. The below works as I want for string values, but how would be best to extend the coverage of ReadAndCheckProperty() to support…
bemo
  • 400
  • 3
  • 11
0
votes
1 answer

System.Text.Json access Json object of json object using c# .net core 3.1

I am calling an api where result is coming this way {{'orderNo':123456}} the same I am trying to access through these codes lines and But it is not working: using System.Text.Json.JsonDocument doc =…
Jay
  • 524
  • 1
  • 7
  • 21