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

JsonSerializer fails to de-serialize DateTimes in Azure Function

I have an Azure Function that receives some JSON from a queue, fx. {"FromDate":"2020-05-26T07:15:00.3714532+00:00","ToDate":"2020-06-25T07:15:00.3714532+00:00"} Using System.Text.Json.JsonSerializer I am trying to de-serialize this JSON into an…
ebug
  • 451
  • 3
  • 18
0
votes
1 answer

Ignore property if exists in System.Text.json. Parameter type is object

I am using .NET Core 3.1 during some application response I am doing object serialization for logging. object result = FromSomeCall(); Logger.DebugFormat("Final Response against {0}", JsonSerializer.Serialize(result.Value)); One object is like { …
Kamran Shahid
  • 3,954
  • 5
  • 48
  • 93
0
votes
0 answers

System.Text.Json JsonSerializer.Deserialize ignortes PropertyNamingPolicy

I'm interfacing with an API which uses snake_case as convention names. I would like to map them to fields which are named with CamelCase. Previously, I've used Newtonsoft.Json's NamingStrategy. A System.Text.Json equivalent seems to be…
Sander K.
  • 41
  • 1
  • 4
0
votes
1 answer

Changing Unix Timestamp of type long? to a nicely looking date while serializing an object to JSON with System.Text.Json

From time to time I need to send a simple email to clients with the data that we store in the objects. However the objects have the date time stored as a long? Unix Timestamp. Obviously this format is not readable for the ordinary mortals and has to…
LilacBlue
  • 173
  • 1
  • 9
0
votes
1 answer

Deserializer Json Format DateTime

I want to read this field from my JSON: create_date: "2020-06-07 15:24:23" This is the property in my class public DateTime? expire_date { get; set; } But this method JsonSeializer.Deserialize can't map this and I get this exception: The…
0
votes
0 answers

Date Converter does not work when serializing with System.Text.Json

I'm creating a Asp.Net Core 3.1 Web Api. I have a need to serialize date without time in a Get method. I read that Asp.Net 3.1 uses System.Text.Json for serialization by default. So, I Added JsonConverter attribute to model property and added a…
frosty
  • 2,421
  • 6
  • 26
  • 47
0
votes
1 answer

Custom JsonConverter (System.Text.Json) producing invalid json

This is the class I want to custom serialize: public class MyClass { public string Key {get; set;} public IEnumerable Value {get; set;} } If I've got a list of it, normal serialization would produce the following output: [ { …
UNeverNo
  • 549
  • 3
  • 8
  • 29
0
votes
1 answer

Adding a property into specified location into json using Newtonsoft.Json

I have a following JSON. I have added 2 x double quotes so that I could declare it as stringvariable in c#, in reality it contains one times double quotes for properties. The complete example code is in this fiddle. I am using Newtonsoft but can use…
learner
  • 581
  • 7
  • 27
0
votes
0 answers

.NET Core 3.1 JsonSerializer fails to deserialize simple JSON

Trying to deserialize a simple JSON string to a Rules object in .NET Core 3.1 using System.Text.Json; namespace Whatever { public class Rules { public SyncResponse SyncResponse; public Rules Load() { var text =…
KBoek
  • 5,794
  • 5
  • 32
  • 49
0
votes
0 answers

Json.Serializer wont serialize + sign

I have this code [Fact] public void TestContactNew() { var options = new JsonSerializerOptions { Encoder = JavaScriptEncoder.Create(UnicodeRanges.All), WriteIndented = true }; …
geckos
  • 5,687
  • 1
  • 41
  • 53
0
votes
1 answer

How to get deserialize object when type discriminator element on root json object using System.Text.Json

Sorry for my poor English. I had success run code from this doc. I got new JSON data and there is another problem. The JSON data is defined like this: { "id": 3, "title": "aaa", "typeDiscriminator": "search", "settingDataTemp": { …
0
votes
0 answers

Get specific element from System.Text.Json array without enumerating

With JsonValueKind.Object you can use: value.GetProperty("XXX") With JsonValueKind.Array you can use: value.EnumerateArray().ElementAtOrDefault(2) But is it also possible to get a specific index without enumerating the array? The reason is that this…
Dirk Boer
  • 8,522
  • 13
  • 63
  • 111
0
votes
1 answer

Can I deserialize a JSON array into properties of a class?

I have a JSON file containing lines like this: {"id":"0258","name":"Canterbury","coordinates":[1.07992,51.27904]} The coordinates item is the geographic coordinates of the city. However it is stored as an array which always contains the [longitude,…
Tim Long
  • 13,508
  • 19
  • 79
  • 147