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

System.Text.Json - Use JsonConverter and JsonConverterAttribute conditionally when calling JsonSerializer.Serialize()

I want to be able to conditionally use a custom JsonConverterAttribute which in turn creates a type of custom JsonConverter when calling JsonSerializer.Serialize() My current implementation means that it works every time a string that has the…
teimaj
  • 314
  • 5
  • 14
0
votes
1 answer

Dapper is accessing all properties of my class when doing a select from the database even when it should not

I am using jquery datatables to display a table of data. The table is only displaying 3 columns from my SqlFunction. I use dapper like this: IQueryable data = null; // Execute my sql statement and map the resultant fields into MyClass…
Dev
  • 31
  • 5
0
votes
1 answer

How to get parent property name in System.Text.Json.Serialization.JsonConverter?

I'm dealing with a 3rd Party API that returns data like this: { "dynamicFields": { "prop1": "val1", "prop2": "val2", "prop3": "val3" }, // otherFields ... } Since these "dynamic fields" are not strongly typed. I want to represent…
brendonparker
  • 838
  • 8
  • 19
0
votes
0 answers

Unescape CJK Letters Like JSON Visualizer Does

I have a custom JSON writer that uses UTF8JsonWriter. No problem sending over internet, writing to disk, and reading back. But now I need some beautifying for console, so I don't want the Asian language character escaping (No \u1234 something...). I…
Jeffrey Goines
  • 935
  • 1
  • 11
  • 30
0
votes
0 answers

System.Text.Json.JsonConverter: How to find out if we are serializing an object or an array in deeper depths(after the first Write() call)?

I am serializing objects (similar to EF entities) or a list of objects that have references to other objects. The references of the objects get serialized, but their references won't be serialized, instead I write an int ID. The problem is that…
kovacs lorand
  • 741
  • 7
  • 23
0
votes
1 answer

Deserialize json on different classes

I have a json with different kind of blocks in it. There are simple block, like text, there's no problems in deserializing them, so I won't cover them up. The problems are with three kind of blocks: media, list and quiz: { "blocks": [ { …
0
votes
1 answer

Deserialization with nested object and in-between step

I am attempting to serialize/deserialze an object using the System.Text.Json JsonSerializer. My container object is a "LicenseFile" which contains a "License" object along with a byte[] digital signature. public class LicenseFile { public…
bdan
  • 91
  • 1
  • 5
0
votes
1 answer

How to deserialize JSON text on the fly in C#

I am reading/receiving blocks of bytes from an async function which I buffer in a MemoryStream and then deserialize to a C# object. public async Task Read() { byte[] block = new byte[1024]; int bytesRead; …
Preli
  • 2,953
  • 10
  • 37
  • 50
0
votes
1 answer

Xamarin Form System.Text.Json.JsonSerializer throws System.TypeInitializationException on iOS only

The following code throws an exception ONLY on iOS - on Android it works as expected: var content = new StringContent( JsonSerializer.Serialize(new { UserName = userName, Password = password }), Encoding.UTF8,…
0
votes
1 answer

Deserializing values I need from large JSON using System.Text.Json Utf8JsonReader

I'm trying to do the following.. Not represent JSON in a POCO Find and Deserialize only the value of a particular property hidden deep within a large JSON using Utf8JsonReader. Filter for JSON tokens : working Following is the code that is…
Arnab
  • 2,324
  • 6
  • 36
  • 60
0
votes
1 answer

JsonIgnore attribute not work in abstract class

I do not want some properties to be saved in the json file, so I used [JsonIgnore] Attribute but Does not work and all properties are saved public abstract class SettingBase { [JsonIgnore] public abstract string FileName { get; set; } …
0
votes
1 answer

how to change newtonsoft.json code to system.text.json

I want to move completely to .NET Core so I need to use System.Text.Json instead of Newtonsoft.Json. How can I write this code in the System.Text.Json? private readonly JsonSerializer _serializer; _serializer = JsonSerializer.Create(new…
hadi khodabandeh
  • 585
  • 2
  • 7
  • 20
0
votes
2 answers

C# Deserialize JSON Schema.org Recipe from web

I'm trying to write a recipe parser in C#. I have tried using both Newtonsoft and System.Text.Json. I have used online json class builders and VS2019 Paste as json classes. I have got the Newtonsoft example code to run. Schema.org Recipe…
Corpuscular
  • 113
  • 6
0
votes
1 answer

how to handle enums like strings and ints

I'm rewriting an api, switching from newtonsoft.json to system.text.json, and an issue i have is the fact that in some cases we send enums as ints and sometimes as strings. Consider this…
Tom
  • 95
  • 2
  • 9
0
votes
1 answer

How can I set the jsonResult.SerializerSettings globally for all calls to JSON()?

When returning data to Telerik.UI.for.AspNet.Core 2021.1.224 Html.Kendo().Grid(), from my RoomController.Read() I must set NumberHandling = JsonNumberHandling.Strict to get the data to display in the Html.Kendo().Grid(). In testing, I have found…
Will
  • 426
  • 3
  • 13