system.text.json Questions
2
Solved
I am in the process of upgrading to ASP.NET Core 3.1, after switching to System.Text.Json noticed strange result variation in floating point values. Upon investigation, I realized System.Text.Json ...
Herbarium asked 20/4, 2020 at 6:27
3
Solved
Wondering if possible to have private constructors and use the new System.Text.Json serializer.
public class MyModel
{
public string Name { get; set; }
public string Data { get; set; }
private...
Bufordbug asked 28/9, 2019 at 15:2
6
Solved
I am shifting my code from .NET Core 2.x to .NET Core 3.x (i.e. use the native library System.Text.Json). In doing this, I ran into some issues with how the former Newtonsoft.Json support for nulla...
Supposal asked 17/12, 2019 at 18:11
4
Here's my JSON:
{
firstName: 'Somebody',
lastName: 'Else'
}
And I deserialize it into JsonElement using these options:
var options = new JsonSerializerOptions {
WriteIndented = true,
PropertyN...
Atheling asked 15/12, 2021 at 15:41
3
Solved
In .NET 6 there are basically two ways of working with JSON DOM:
using an immutable JSON DOM via the JsonDocument class
using a mutable JSON DOM via the JsonNode class
more informations about thi...
Karlik asked 20/7, 2022 at 7:48
2
Solved
I have an endpoint in .NET 6 Microsoft.NET.Sdk.Web project that deserialize query strings into a .NET object by using the standard [FromQuery]
[Route("[controller]")]
public class Samples...
Lattice asked 6/7, 2022 at 16:6
4
Solved
I don't believe I am wrapping my head around how to properly use JsonConverter for polymorphism in parsing json results.
In my scenario, I am targeting Git Policy Configurations in TFS. A policy ...
Broadminded asked 21/3, 2020 at 19:24
1
Solved
I am working on migrating from Json.Net to System.Text.Json. I am not sure how we can build json object like below code using System.Text.Json. I tried lots of workaround but nothing seems working....
Lemmueu asked 16/6, 2022 at 4:26
1
Solved
I have the following simple classes :
public abstract class GitObject
{
public Repository Repository { get; set; }
public abstract string Serialize();
public abstract void Deserialize(string dat...
Hiatt asked 25/4, 2022 at 14:9
1
System.Text.Json.JsonSerializer.DeserializeAsyncEnumerable<T> is a method by System.Text.Json that can take a Stream and produce an IAsyncEnumerable<T>, where the enumeration can be asy...
Pruitt asked 31/5, 2022 at 17:4
2
Solved
I have an ASP.NET Core Web API project using .Net Framework 4.7 and I'm upgrading to .Net Core 3.1. One of the reasons that I'm upgrading is to use the new System.Text.Json serializer.
Currently,...
Hortensiahorter asked 8/1, 2020 at 17:23
3
Solved
I need to iterate through an JsonDocument and perform some sort of check depending on the JsonValueKind I encounter.
I tried to do this validation check in such manner:
public bool Dec(JsonElement ...
Styracaceous asked 3/4, 2020 at 8:56
5
{
"TestData":{
"Year__of__Account":"2019",
"Tax___x0025_":"0.06",
"Buildings__1":"1000",
"Contents__1":"400",
"Total_Insurable_Value":"100",
"Buildings__Prem":"2560.8",
"Contents__Prem":"1...
Cesaro asked 9/10, 2019 at 10:51
2
Solved
JSON serializer returns an empty JSON object.
using System.Text.Json;
(int, int) tuple1 = (1, 2);
var token = JsonSerializer.Serialize(tuple1); // return empty object {}
(int item1, int item2) tu...
Pastel asked 21/12, 2021 at 14:2
5
Solved
I am consuming an API that is supposed to return an object, like
{
"some_object": {
"some_field": "some value"
}
}
when that object is null, I would expect
{
"some_object": null
}
or
...
Coprophagous asked 31/1, 2020 at 22:56
2
I have an abstract class named Extension which has several derived classes such as DerivedExtensionA, DerivedExtensionB, etc.
Now I have a list defined as List<Extension> which contains the d...
Consternate asked 30/3, 2022 at 21:59
8
Solved
I'm preparing a migration from ASP.NET Core 2.2 to 3.0.
As I don't use more advanced JSON features (but maybe one as described below), and 3.0 now comes with a built-in namespace/classes for JSON, ...
Cavite asked 1/7, 2019 at 11:40
1
I have upgraded my version of .Net Core from preview 2 to preview 6 which has broken a couple of things. Most significant is that I cannot use newtonsoft JSON anymore.
AddNewtonsoftJson in Configu...
Frances asked 27/8, 2019 at 2:46
1
I have some classes that I want to (de-)serialize:
public class Top
{
public Top(Sub content) { Content = content; }
public Sub Content { get; init; }
}
public class Sub
{
public Sub(Sub? entr...
Karykaryl asked 9/3, 2022 at 9:17
4
I want to know the equivalent of the ToObject<>() method in Json.NET for System.Text.Json.
Using Json.NET you can use any JToken and convert it to a class. For example:
var str = ""...
Maiden asked 27/9, 2019 at 17:3
2
Solved
Consider .NET 6's System.Text.Json.JsonSerializer.Deserialize method and its many overloads.
Each one returns either object? or TValue? which indicates that null could be returned. However, the doc...
Virtue asked 17/2, 2022 at 17:1
2
Solved
I have a webapi that returns some Json:
{"id":9,"businessName":"dummy","address":"pluto","products":[
{"id":762,"descripti...
Whipcord asked 17/2, 2022 at 12:24
2
Solved
I have a simple JSON I would like to rename (probably by copying then removing) a key. .NET Fiddle:
const string input = @"{ ""foo"": [{""a"": 1}, {&qu...
Hayner asked 17/2, 2022 at 2:24
1
Solved
I need to convert a JsonElement to string but without any carriage return, tabs or spaces. A simple ToString() works but leaves those in:
data.ToString()
Results:
"{\r\n "Field1&q...
Steels asked 15/2, 2022 at 18:8
5
Solved
I have a json that the new System.Text.Json.JsonSerializer.Deserialize<T>(json_data) serialize as List<T> with the correct numbers of elements, but then the objects inside have all the ...
Kegan asked 15/11, 2019 at 14:36
© 2022 - 2024 — McMap. All rights reserved.