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

System.Text.Json to deserialize to an object that is a List

I am trying to switch over to System.Text.Json and I had some converters that don't seem to be portion over very well. My classes are all based on "pure" interfaces so I have a lot of List and I'm running into a brick wall trying to resolve it. With…
-1
votes
2 answers

C# System.Text.Json Can't deserialize response from open sky api. My DTO model doesn't fit

C# System.Text.Json Can't deserialize response from open sky api. My DTO model doesn't fit I have response body like this and i can't desearilize it to c# dto model: { "time": 1677521877, "states": [ [ "a2e5ec", …
-1
votes
1 answer

System.Text.Json JsonSerializer.Deserialize throws "Each parameter in the deserialization constructor..." exception

I have the following classes: public class BaseResponse { public bool Success { get; set; } public string Message { get; set; } public BaseResponse(bool success, string message) { Success = success; Message =…
PiousVenom
  • 6,888
  • 11
  • 47
  • 86
-1
votes
2 answers

Using a Custom Enum Json Converter

I am looking to create a custom JSON converter on my C# application. When I instantiate a new class I am unable to leave it generic. Class: using System.Text.Json; using System.Text.Json.Serialization; public class Converter : JsonConverter
-1
votes
1 answer

How to automatically deserialize a JSON property value when the value is a double-serialized escaped JSON string?

Let's say I have the following type: class Foo{ public T data {get;init;} } and I want to use this type in multiple controllers: [HttpPost] public async void Post(Foo myFoo){ myFoo.data // this is SomeComplexClass //…
Brandon Piña
  • 614
  • 1
  • 6
  • 20
-1
votes
2 answers

How to set JsonSerializerOption per request

I have a .NET 7 web api with a route that returns Users. public class User { public Guid? Id { get; set; } public String? Name { get; set; } public Int32? Age { get; set; } public String? HairColor { get; set; } } If "Name" comes in…
ScubaSteve
  • 7,724
  • 8
  • 52
  • 65
-1
votes
3 answers

Dictionary is not being serialized

I am trying to serialize a simple class: public class Offer_RPC { /// /// this dictionary contains your requested additions ans substractions, in mojos.
/// if you wan to offer an nft for example, use the launcher id such…
julian bechtold
  • 1,875
  • 2
  • 19
  • 49
-1
votes
2 answers

System.Text.Json.JsonException: The JSON value could not be converted to System.Collections.Generic.List`1[System.Collections.Generic.List`1

I'm a beginner in C# development and I need your help.. I am checking all the subject in Stackoverflow but I can't find and fix my problem. I received a JSON response from an API and I would like to transform the data in object. ------------ Here my…
-1
votes
1 answer

how to get a value from json with just the index?

Im making an app which needs to loop through steam games. reading libraryfolder.vbf, i need to loop through and find the first value and save it as a string. "libraryfolders" { "0" { "path" "D:\\Steam" "label" "" …
Lachie
  • 5
  • 3
-1
votes
1 answer

Deserialise JSON to Dictionary tree

In PHP and Python I can deserialise a JSON document to a dictionary structure. That's the default behaviour and there are not many other options anyway. In C#, hovever, all is typed and System.Text.Json methods want to know what type to deserialise…
ygoe
  • 18,655
  • 23
  • 113
  • 210
-1
votes
1 answer

How do I parse this Json which is completely variable in structure

I'm trying to parse a section of a json document using System.Text.Json in C# (.NET 6). I have used the following to grab the relevant section from the api response: string jsonString = await httpClient.GetStringAsync(url); string fieldsetJsonString…
trueimage
  • 309
  • 2
  • 4
  • 14
-1
votes
2 answers

InvalidOperationException: Cannot get the value of a token type 'String' as a number

Trying to get data from products.json file and store it in Products[] mention in file JsonFileProductServices.cs but getting this error 'The JSON value could not be converted to System.Int32. Path: $[0].id | LineNumber: 2 | BytePositionInLine:…
Hamza Khan
  • 13
  • 6
-1
votes
2 answers

Converting JSON data from an API to a C# object

I'm trying to convert JSON data from an API to a c# object and I am getting the following error: The JSON value could not be converted to CountriesDemo.Models.CountryModel. Path: $ | LineNumber: 0 | BytePositionInLine: 1 My function: public static…
ChrisJ
  • 477
  • 2
  • 15
  • 31
-1
votes
1 answer

Serialization in C# didn't serialize all the information (ex. I got name and dateOfBirth of person but not gender)

The code for serialization is: using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Text.Json; namespace TxtToXmlParser.Parser { public static class JSONserializerService { public static…
user19460705
-1
votes
1 answer

How to html encode Json response in ASP.NET Core?

I am looking into Stored Cross-site Scripting vulnerabilities that occur when the data provided by an attacker is saved on the server, and is then displayed upon subsequent requests without proper HTML escaping. I have NET 5 ASP.NET Core application…
LP13
  • 30,567
  • 53
  • 217
  • 400