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

NewtonSoft.Json Treating Blank Value as Null but not throwing error

Environment .net 7 Using Both System.Text.Json Also NewtonSoft.Json ( 13.0.2) Example code string str = @"{ ""DateTimeNull"":"""" }"; try { var t = System.Text.Json.JsonSerializer.Deserialize(str); } catch (JsonException ex) { …
dotnetstep
  • 17,065
  • 5
  • 54
  • 72
0
votes
0 answers

How can I register IJsonTypeInfoResolver in the WEB API application?

System.Text.Json 7.0 has provided the new and long awaited interface IJsonTypeInfoResolver. In this nice article one can find several helpful examples. The problem appears when I try to register it in my Web API application. I have my…
Alex Kovanev
  • 1,858
  • 1
  • 16
  • 29
0
votes
2 answers

Entity Framework : reference loop in many to many relationship

I have this three entities Customer, Product and Review. A customer can have many products, and a product can have only one customer as owner. A customer can also have many reviews, and one review can have only one customer. A product can have many…
Sachihiro
  • 1,597
  • 2
  • 20
  • 46
0
votes
1 answer

How does one set JsonSerializerOptions.DefaultIgnoreCondition for Serilog.Sinks.Seq

I'm using Serilog.Sinks.Seq in my C# app (see the configuration code below) but I can't figure out how to set the JsonSerializerOptions.DefaultIgnoreCondition to ignore nulls. Any help in this regard would be greatly appreciated... using IHost host…
0
votes
3 answers

Convert nested object Id to object when deserializing JSON

*** Edit: Clarified there are two, separate JSON files *** I have two classes: public class Phone { public int PhoneId { get; set; } public string Name { get; set; } public Manufacturer PhoneManufacturer { get; set; } } public…
ml123
  • 1,059
  • 2
  • 12
  • 27
0
votes
1 answer

Selectively exclude a property on one JSON serialization but not on another

I have a POCO like this public class Foo { public string PartitionKey => $"foo-{Bar}"; public string Bar { get; set; } } I'm storing that POCO as serialized JSON in a database (Azure Cosmos DB to be specific) and making it available to…
silent
  • 14,494
  • 4
  • 46
  • 86
0
votes
2 answers

How to read values from JsonNode in System.Text.Json

I want to serialize a refresh token and send it to the client. Then on return, I want to deserialize and read it. Here's my code. using System.Text.Json; using System.Dynamic; using System; using System.Text.Encodings.Web; using…
Mohammad Miras
  • 143
  • 1
  • 9
0
votes
2 answers

ASP.NET Core - StringEnumConverter - ONLY Allow Strings

Is there a way to forbid integers passed in as enums without resorting to a string property type? I already do the following: return builder.AddJsonOptions(options => { var namingPolicy = JsonNamingPolicy.CamelCase; // omitted... …
karczilla
  • 105
  • 2
  • 12
0
votes
2 answers

How to accept JsonArray as input to WebAPI

I am using .Net 6 WebAPI. I need to accept a generic JSON array as input. The properties present in each JSON document is not known before. So I cannot Deserialize to specific object type. So I am looking for 2 inputs. a) What should be input…
askids
  • 1,406
  • 1
  • 15
  • 32
0
votes
1 answer

How to deserialize JSON array with changeable number of subarrays using System.Text.Json in C#

Is it possible to automatically deserialize JSON to an array of arrays even if that JSON sometimes only contains one array element and thus doesn't technically represent an array of arrays but a single array element? The json is a chart that should…
GI1
  • 116
  • 8
0
votes
1 answer

(type))JsonSerializer.Deserialize(input, typeof(type)) vs JsonSerializer.Deserialize(response)

I have a question regarding System.Text.Json: there are 2 Primary functions to deserialize: MyClass deserialized = (MyClass)JsonSerializer.Deserialize(response, typeof(MyClass)); MyClass deserialized2 =…
julian bechtold
  • 1,875
  • 2
  • 19
  • 49
0
votes
2 answers

Is there a neat way to recursively hunt through every Json property in a document and apply rounding to any Numeric types

I need to be able to apply Math.Round to every Number in a JSON document. I don't have any control over the original writer of the JSON document so my input is a string. The numbers can be within JSON objects themselves which in turn could be within…
Dutts
  • 5,781
  • 3
  • 39
  • 61
0
votes
0 answers

How to put condition on Custom Json Convertor

I have defined a custom Json Convertor for my DTO as below public class CustomJsonConverter : JsonConverter where T : class { public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) …
0
votes
0 answers

What is the System.Text.Json alternative to XmlElementAttribute("Emp", GetType(Employee))

I have a class as below with the property of type object. Earlier I used to assign class dynamically to object property Item as below using XmlElementAttribute. [Serializable] public class Employee { public int EmployeeID { get;…
0
votes
0 answers

How to serialize complex object, which have a custom data type matrix?

I need to serialize a class object whose field is a custom data type matrix, like: internal class MyClass { private readonly MyMatrix[,] myField; public MyField { get => myField; } } I am using json serialization code from here:…
Alexey
  • 3
  • 2