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

Need help deserializing C# / .NET 6 into seperate objects

I am attempting to use JsonSerializer.Deserialize() from System.Text.JSON in .NET 6. I have no control over the format of the JSON. I have used it successfully in the past but now the data I need to consume is more complicated (but not VERY…
Señor CMasMas
  • 4,290
  • 2
  • 14
  • 21
0
votes
0 answers

Add JsonObject to JsonArray

I am using System.Text.Json My sample json is { "a": {} } I am reading key "a" from json and converting JsonNode to JsonObject. JsonObject jsonObject = jsonForTest.AsObject(); JsonArray array = new JsonArray(); …
Ankur
  • 21
  • 5
0
votes
1 answer

Can't get the desired properties via JsonPath evaluate method

I have a json schema that marks special properties in need of processing and I want to query those via JsonPath.Evaluate. Here's a part of the schema to illustrate the issue { "type": "object", "properties": { "period": { …
Pavel Ronin
  • 576
  • 4
  • 11
0
votes
2 answers

How can I serialize a property in an inherited ICollection class?

I have a class that presented like public class ItemCollection : ICollection { public ItemCollection() { Items = new List(); } public List Items { get; set; } ... } Now it will be serialized into: { …
KAMyAw
  • 21
  • 3
0
votes
3 answers

Have a JsonConverter that is only used during deserialization

My goal is to deserialize this JSON into a Dictionary. [ { "key": "foo", "value": 42 } ] My approach is a custom JsonConverter> with an appropriate JsonConverterFactory. Deserialization is…
wertzui
  • 5,148
  • 3
  • 31
  • 51
0
votes
1 answer

System.Text.Json Contract resolver

I was implementing a unit test to invoke a PATCH endpoint, using "System.Text.Json" to serialize the data and send it as content. I was always getting BAD REQUEST, until I found out that the serializer encapsulates the whole patch document inside…
user18588835
0
votes
1 answer

Deserialise JSON data from external api and return a leaner JSON data

I am practicing with web api. My goal is to create a Get endpoint, which receive data from an external api, then return a leaner result. external api link: https://www.themealdb.com/api/json/v1/1/search.php?f=a, The external api data looks like: { …
0
votes
0 answers

JSON serialization of object with a base class list

I am working on a Blazor app that uses the local storage. I want to JSON serialize this data-structure: The XML serializer does this without a hitch, but de JSON serializer does not include any type-info, so my C's and D's are downgraded to the…
k.c.
  • 1,755
  • 1
  • 29
  • 53
0
votes
0 answers

Serializing property with dynamic name and Required annotation

I have a class that is used for collection responses: public class CollectionResponse { [JsonExtensionData] public Dictionary Items { get; } = new(1); public CollectionResponse(string name, IEnumerable objects) …
convexmethod
  • 264
  • 2
  • 8
0
votes
0 answers

How to use System.Text.Json to deserialize fields that have implicit conversion (implicit operator)?

I have an Optional struct that defines an implicit conversion from the original type: public readonly struct Optional { // Some code removed to make the example simpler: original code:…
Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
0
votes
1 answer

System.Text.Json Serialize List> dynamically

I am developing a test using SpecFlow and I am obtaining test arguments via ScenarioContext object. I want to Serialize an object of type List>, to produce the output as below: "TestCaseArguments":[ {"First…
Kartik Javali
  • 327
  • 1
  • 4
  • 11
0
votes
3 answers

Serializing and deserializing IReadOnlyCollection using System.Text.Json

I have a (C#) object that I want to serialize using the .NET 6 System.Text.Json serializer. My object looks like so: private List _substitutions; public string? Name { get; private set; } public string EmailAddress { get; private set;…
Eduard Keilholz
  • 820
  • 8
  • 27
0
votes
0 answers

Can .net web api throw exception for request with invalid Enum other than set the request to null?

we have a web api in .net 6 public async Task SeriesDataV21([FromBody] SeriesDataRequest seriesDataRequest) { } The request object SeriesDataRequest has an enum and I added a converter to accept string.…
daxu
  • 3,514
  • 5
  • 38
  • 76
0
votes
1 answer

how to workaround newtonJson and System.Text.Json differences

We are trying to migrate some old .net framework projects to .net 6. The old .net projects use newton Json to deserialize or serialize and we found some behaviour differences in System.Text.Json. For example, for this object: { "Codes": [ …
daxu
  • 3,514
  • 5
  • 38
  • 76
0
votes
2 answers

How to Deserialize response from RestSharp using System.Text.Json?

I am trying to write simple Get operation using RestSharp and trying to use System.Test.Json to deserialize the response. My Test method is as follows, [Test] public void Test1() { var restClient = new…
Wicky
  • 118
  • 2
  • 13