You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With default options, input <xref:System.DateTime> and <xref:System.DateTimeOffset> text representations must conform to the extended ISO 8601-1:2019 profile.
36
-
Attempting to deserialize representations that don't conform to the profile will cause <xref:System.Text.Json.JsonSerializer> to throw a <xref:System.Text.Json.JsonException>:
35
+
With default options, input <xref:System.DateTime> and <xref:System.DateTimeOffset> text representations must conform to the extended ISO 8601-1:2019 profile. If you attempt to deserialize representations that don't conform to the profile, <xref:System.Text.Json.JsonSerializer> throws a <xref:System.Text.Json.JsonException>:
The <xref:System.Text.Json.JsonDocument> provides structured access to the contents of a JSON payload, including <xref:System.DateTime>
41
-
and <xref:System.DateTimeOffset> representations. The following example shows how to calculate the average
39
+
<xref:System.Text.Json.JsonDocument> provides structured access to the contents of a JSON payload, including <xref:System.DateTime> and <xref:System.DateTimeOffset> representations. The following example shows how to calculate the average
42
40
temperature on Mondays from a collection of temperatures:
Attempting to compute the average temperature given a payload with non-compliant <xref:System.DateTime> representations will cause <xref:System.Text.Json.JsonDocument>to throw a <xref:System.FormatException>:
44
+
If you attempt to compute the average temperature given a payload with non-compliant <xref:System.DateTime> representations, <xref:System.Text.Json.JsonDocument>throws a <xref:System.FormatException>:
@@ -67,8 +65,12 @@ Attempting to read non-compliant formats with <xref:System.Text.Json.Utf8JsonRea
67
65
68
66
### When using <xref:System.Text.Json.JsonSerializer>
69
67
70
-
If you want the serializer to perform custom parsing or formatting, you can implement [custom converters](xref:System.Text.Json.Serialization.JsonConverter%601).
71
-
Here are a few examples:
68
+
If you want the serializer to perform custom parsing or formatting, you can implement [custom converters](xref:System.Text.Json.Serialization.JsonConverter%601). The following sections show a few examples:
69
+
70
+
-[DateTime(Offset).Parse and DateTime(Offset).ToString](#datetimeoffsetparse-and-datetimeoffsettostring)
71
+
-[Utf8Parser and Utf8Formatter](#-and-)
72
+
-[Use DateTime(Offset).Parse as a fallback](#use-datetimeoffsetparse-as-a-fallback)
73
+
-[Use Unix epoch date format](#use-unix-epoch-date-format)
72
74
73
75
#### DateTime(Offset).Parse and DateTime(Offset).ToString
74
76
@@ -135,7 +137,7 @@ and then written with the <xref:System.Text.Json.Utf8JsonWriter.WriteStringValue
135
137
### When using <xref:System.Text.Json.Utf8JsonReader>
136
138
137
139
If you want to read a custom <xref:System.DateTime> or <xref:System.DateTimeOffset> text representation with <xref:System.Text.Json.Utf8JsonReader>,
138
-
you can get the value of the current JSON token as a <xref:System.String> using <xref:System.Text.Json.Utf8JsonReader.GetString> method, then parse the value using custom logic.
140
+
you can get the value of the current JSON token as a <xref:System.String> using the <xref:System.Text.Json.Utf8JsonReader.GetString> method, then parse the value using custom logic.
139
141
140
142
The following example shows how a custom <xref:System.DateTimeOffset> text representation can be retrieved using the <xref:System.Text.Json.Utf8JsonReader.GetString> method,
141
143
then parsed using <xref:System.DateTimeOffset.ParseExact(System.String,System.String,System.IFormatProvider)>:
@@ -146,24 +148,23 @@ then parsed using <xref:System.DateTimeOffset.ParseExact(System.String,System.St
146
148
147
149
### Date and time components
148
150
149
-
The extended ISO 8601-1:2019 profile implemented in <xref:System.Text.Json?displayProperty=fullName> defines the following components for
150
-
date and time representations. These components are used to define various supported levels of granularity
151
+
The extended ISO 8601-1:2019 profile implemented in <xref:System.Text.Json?displayProperty=fullName> defines the following components for date and time representations. These components are used to define various supported levels of granularity
151
152
when parsing and formatting <xref:System.DateTime> and <xref:System.DateTimeOffset> representations.
Copy file name to clipboardExpand all lines: docs/standard/serialization/system-text-json/migrate-from-newtonsoft.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -23,8 +23,8 @@ The `System.Text.Json` namespace provides functionality for serializing to and d
23
23
* .NET Framework 4.6.2 and later versions
24
24
* .NET Core 2.0, 2.1, and 2.2
25
25
26
-
>[!TIP]
27
-
> You can use AI assistance to [migrate from `Newtonsoft.Json` with GitHub Copilot](#use-github-copilot-to-migrate).
26
+
>[!TIP]
27
+
> You can use AI assistance to [migrate from `Newtonsoft.Json`](#use-github-copilot-to-migrate).
28
28
29
29
`System.Text.Json` focuses primarily on performance, security, and standards compliance. It has some key differences in default behavior and doesn't aim to have feature parity with `Newtonsoft.Json`. For some scenarios, `System.Text.Json` currently has no built-in functionality, but there are recommended workarounds. For other scenarios, workarounds are impractical.
30
30
@@ -380,7 +380,7 @@ Starting in .NET 7, you can use the C# `required` modifier or the <xref:System.T
380
380
* The `DateTimeZoneHandling` setting can be used to serialize all `DateTime` values as UTC dates.
381
381
* The `DateFormatString` setting and `DateTime` converters can be used to customize the format of date strings.
382
382
383
-
<xref:System.Text.Json?displayProperty=fullName> supports ISO 8601-1:2019, including the RFC 3339 profile. This format is widely adopted, unambiguous, and makes round trips precisely. To use any other format, create a custom converter. For example, the following converters serialize and deserialize JSON that uses Unix epoch format with or without a time zone offset (values such as `/Date(1590863400000-0700)/` or `/Date(1590863400000)/`):
383
+
<xref:System.Text.Json> supports ISO 8601-1:2019, including the RFC 3339 profile. This format is widely adopted, unambiguous, and makes round trips precisely. To use any other format, create a custom converter. For example, the following converters serialize and deserialize JSON that uses Unix epoch format with or without a time zone offset (values such as `/Date(1590863400000-0700)/` or `/Date(1590863400000)/`):
Copy file name to clipboardExpand all lines: docs/standard/serialization/system-text-json/snippets/how-to-contd/csharp/CustomConverterInferredTypesToObject.cs
Copy file name to clipboardExpand all lines: docs/standard/serialization/system-text-json/snippets/how-to-contd/csharp/CustomConverterPreserveReferences.cs
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -101,7 +101,7 @@ class MyReferenceHandler : ReferenceHandler
0 commit comments