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

How to output a formatted string from a JSON model class

I want something like the following: using System; using System.Text; using System.Text.Json; public class Program { public static void Main() { var myArgs = new ArgClass(); // myArgs is populated via…
master_ruko
  • 629
  • 1
  • 4
  • 22
-1
votes
1 answer

Request Model is null when I post it to API

I'm facing a problem doing post requests via .Net6 Web API. I'm a bit confused about it. Since .Net6 we prefer to use System.Text.Json in place of Newtonsoft.Json I have one Bool property in Request Model "isAPRenew" If I am passing "isAPRenew":…
-1
votes
1 answer

Migrating from NewtonSoft.Json to System.Text.json

We have an POST endpoint which accepts dictionary as request body. public class A { public IDictionary? Values { get; set; }; } Earlier we were accepting JToken. We have replaced JToken with JsonElement during…
-1
votes
1 answer

JsonDocument API throws an exception "The requested operation requires an element of type 'Object', but the target element has type 'Array'"

JsonDocument.Parse throws The requested operation requires an element of type 'Object', but the target element has type 'Array'., because the message is actually an array. You can see that in the log below. How can I deal with it? My code: private…
nop
  • 4,711
  • 6
  • 32
  • 93
-1
votes
3 answers

Parse json document to extract node's value without knowing root property name in C#( .net core)

Is there a better way to parse json document and extract property value of a particular node in C#(.net core), without knowing root property's name? Given: - root of json document will have only one property but property name is unknown. Would…
Subasish
  • 92
  • 11
-1
votes
2 answers

Using System.Text.Json, how do I get a "object" out of a extension data object?

I have a class written for ProblemDetails. I switched from NewtonSoft to System.Text.Json. I am trying to get the list of "errors", which is a deserialized into the Extensions property, which is decorated with [JsonExtensionData]. I cannot figure…
Tim Bassett
  • 1,325
  • 1
  • 12
  • 23
-1
votes
2 answers

How to deserialize a nested json string?

Suppose I have this classes: internal class Test { public string value { get; set; } public Test(string value) { this.value = value; } } public class Response { private string errorMessage { get; } private T…
D4NieLDev
  • 260
  • 1
  • 3
  • 14
-1
votes
1 answer

How to read an unformatted json stream and write to a formatted json file with minimal memory usage?

I'm calling an API that return a response of type application/json. The response can be very tiny but it can be very huge, 500mb to 700mb. I would like to format the content (indentation, new lines, etc) and write the response to a json file with…
Alexandre Jobin
  • 2,811
  • 4
  • 33
  • 43
-1
votes
2 answers

System.Text.Json Converter to change string property to float

Given the following json document, what would be the best way to convert it to a valid object using a Converter? The trick comes in that the source json has the value property as string where it should be serialized as a float? { "metric":…
mieliespoor
  • 945
  • 2
  • 8
  • 23
-1
votes
1 answer

polymorphic Json deserialization in nested scenario

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? entry) { Entry = entry; Type = SubType.super;…
Kjara
  • 2,504
  • 15
  • 42
-1
votes
1 answer

Import deserialized System.Text.Json data into current type

I want to import json data from within the class which is the target of the deserialization. Is this possible with System.Text.Json without additional mapping? Ideally I would use "this" instead of the generic type parameter. I know that is…
TvdH
  • 1,088
  • 14
  • 29
-1
votes
1 answer

Web Api serializer serialize object to camel-case json

Please consider this code: var ResultMaster = new Master() { Id = Result.Id, CityCode = Result.CityCode, Desc = Result.Desc, EmployeeId = Result.EmployeeId, IsDelete = Result.IsDelete, LastChange = Result.LastChange, …
Arian
  • 12,793
  • 66
  • 176
  • 300
-1
votes
1 answer

Use Json.Net instead of Syste.Text:Json in .NET 6

We want to use Json.Net instead System.Text.Json in our project, mainly because we must use the TypeNameHandling function. The app has the following: It's a console app. It uses Dependency Injection. Question: how can we tell the runtime to use…
Attilio Gelosa
  • 555
  • 1
  • 8
  • 23
-1
votes
1 answer

Serialize a generic list with properties of different type of classes

I have the following code using System; using System.Collections.Generic; using System.Text.Json; public class Program { public static void Main() { Console.WriteLine("Hello World"); var shapes = new List(); …
Zoinky
  • 4,083
  • 11
  • 40
  • 78
-1
votes
1 answer

Quickly finding out if element contains JSON formatted data in C# .Net 6

What would be the most efficient way in C# .Net 6 to determine if an element or string contains JSON formatted data. Will have billions of rows to search through and didn't know if using JSON.Net, System.JSON or a regex expression, or other way…
SuperDave
  • 373
  • 5
  • 14