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
0 answers

How to create a JsonConverter that instantiates a given object type based on an inner field using System.Text.Json

Given the following json { "filters": [ { "filterType": "fooFilter", "min": 1, "max": 5, "size":3 }, { "filterType": "barFilter", "multiplier": "1.953283", "average": "5.732837" }, { "filterType": "bazFilter", "limit": 10,…
Aaron Murray
  • 1,920
  • 3
  • 22
  • 38
0
votes
2 answers

System.Text.Json, JsonConverter not called

I wrote a test programe with .NET 6 static void Main(string[] args) { JsonSerializerOptions options = new JsonSerializerOptions() { Converters = { new JsonStringEnumConverter(), …
martinrhan
  • 362
  • 1
  • 18
0
votes
0 answers

Get Line/Col info from System.Text.Json.JsonElement

I have some 3rd part code that requires a System.Text.Json.JsonElement, but I need to get line numbers for the System.Text.Json.JsonElement objects it passes back to me. Basically I'm using JsonSchema.Net to validate a JSON document, and I want to…
Sprotty
  • 5,676
  • 3
  • 33
  • 52
0
votes
1 answer

Converting dynamic property to json dictionary type

I have the "json" mentioned below. "changes" property is changeable {"sort":[{"field":"recid","direction":"desc"}],"changes":[{"recid":2084,"LokasyonAdresi":"211","LokasyonAdi":"111"}],"action":"save"} When I convert json to c# classes, the…
0
votes
0 answers

System.Text.Json Serialization formatting issues

In my ASP.NET Core application I am using the built-in System.Text.Json serializer to convert EF models to DTOs. On one of my models, I have a property that represents a percentage and I map that to a DTO property. Before returning the value to the…
0
votes
3 answers

text.json deserialize i get a error c# conversion error

I am pulling data from API. I am getting an error while deserializing. please help me. error: System.Text.Json.JsonException: '',' is invalid after a single JSON value. Expected end of data. Path: $ | LineNumber: 0 | BytePositionInLine: 128.' data…
0
votes
1 answer

Change feed iterator content deserialization

Currently, I'm looking for ways to deserialize entities from Change Feed Iterator content with System.Text.Json. I found this example from the documentation, but it uses Newtonsoft.Json and I don't like an approach with JObject and…
0
votes
0 answers

How to serialize an object to a string conditionally in System.Text.Json

I have an object: Link : Entity that sometimes should be serialized to, or from, just a plain string of text. Other times its should just serialize like any other entity, using the attributes and class/property data under Link and Entity. Below is…
SuperMeip
  • 65
  • 3
  • 9
0
votes
1 answer

use System.Text.Json to serialize an Object as a single String conditionally

I'm working on an ActivityPub implimentation in c#, and sometimes links are "strings" like a url link, and sometimes links are objects with a Link sub-type. (Link : Entity) I'm wondering if there's a possible way to use System.Text.Json to serialize…
SuperMeip
  • 65
  • 3
  • 9
0
votes
0 answers

JSON Serialization of Type

I'm trying to serialize an object that has a Type property into JSON. By default this isn't allowed due to security concerns, so I'm wondering if it's possible with an explicit converter (or if it's not even a good idea). Here is the converter I…
0
votes
2 answers

.Net System.Text.Json cannot serialize object

I can't serialize BaseResponse object. But Device object serialized successfully. I didnt find reason var data = new BaseResponse(); var json1 = JsonSerializer.Serialize(data); var data2 = new Device(); var json2 =…
ikbalkazanc
  • 161
  • 1
  • 8
0
votes
1 answer

Migrating Newtonsoft.Json code to System.Text.Json

How do I migrate the following method from Newtonsoft.Json to System.Text.Json? You can see what I tried below, but JsonDocument seems to be disposable and I wonder if there is a better solution close to JObject, which doesn't inherit…
nop
  • 4,711
  • 6
  • 32
  • 93
0
votes
2 answers

Flattening a nested dictionary with System.Text.Json

I'm trying to port the last piece of code I have that is dependent on Newtonsoft.Json to System.Text.Json. The code parses a JSON fragment and flattens it. This is generated by a legacy system so we'd rather not change that if possible. // Comment…
Sam
  • 4,219
  • 7
  • 52
  • 80
0
votes
1 answer

System.Text.Json - Unable to deserialize

I'm using System.Text.Json and for some reason it recently broke and doesn't want to deserialize it. This is the exception I'm getting: {"The JSON value could not be converted to QSGEngine.Web.Exchanges.Exchanges.Binance.AccountTradeResponse. Path:…
nop
  • 4,711
  • 6
  • 32
  • 93
0
votes
1 answer

System.Text.Json - failing to deserialize a REST response

I'm trying to implement the following API Endpoint. Due to the fact, System.Text.Json is now preferred over Newtonsoft.Json, I decided to try it. The response clearly works, but the deserialization doesn't. Response https://pastebin.com/VhDw5Rsg…
nop
  • 4,711
  • 6
  • 32
  • 93