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
* Revise AI highlight example
* Fix build warning
* Updates per feedback
* Updates per Mike's feedback
Removed redundant text about using AI tools for migration and streamlined the example prompt section.
Copy file name to clipboardExpand all lines: docs/standard/serialization/system-text-json/migrate-from-newtonsoft.md
+12-16Lines changed: 12 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: "Migrate from Newtonsoft.Json to System.Text.Json - .NET"
3
3
description: "Learn about the differences between Newtonsoft.Json and System.Text.Json and how to migrate to System.Text.Json."
4
4
no-loc: [System.Text.Json, Newtonsoft.Json]
5
-
ms.date: 02/11/2025
5
+
ms.date: 10/03/2025
6
6
helpviewer_keywords:
7
7
- "JSON serialization"
8
8
- "serializing objects"
@@ -24,7 +24,7 @@ The `System.Text.Json` namespace provides functionality for serializing to and d
24
24
* .NET Core 2.0, 2.1, and 2.2
25
25
26
26
> [!TIP]
27
-
> You can use AI assistance to [migrate from `Newtonsoft.Json`](#use-ai-to-migrate).
27
+
> You can use AI assistance to [migrate from `Newtonsoft.Json`](#use-ai-for-solution-wide-migration).
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
@@ -639,26 +639,22 @@ System.Text.Json sets limits that can't be changed for some values, such as the
639
639
640
640
Newtonsoft parses `NaN`, `Infinity`, and `-Infinity` JSON string tokens. With System.Text.Json, use <xref:System.Text.Json.Serialization.JsonNumberHandling.AllowNamedFloatingPointLiterals?displayProperty=nameWithType>. For information about how to use this setting, see [Allow or write numbers in quotes](invalid-json.md#allow-or-write-numbers-in-quotes).
641
641
642
-
## Use AI to migrate
642
+
## Use AI for solution-wide migration
643
643
644
-
You can use AI tools, such as GitHub Copilot, to migrate your code from `Newtonsoft.Json` to `System.Text.Json` within your IDE. You can customize the prompt per your requirements.
644
+
You can use AI tools, such as GitHub Copilot, to help with migrating your solution code from `Newtonsoft.Json` to `System.Text.Json`.
645
645
646
-
**Example prompt for Copilot Chat**
646
+
Here's an example prompt you can use in Visual Studio Copilot Chat to migrate a solution.
647
647
648
648
```copilot-prompt
649
-
convert the following code to use System.Text.Json
650
-
Product product = new Product();
651
-
652
-
product.Name = "Apple";
653
-
product.ExpiryDate = new DateTime(2024, 08, 08);
654
-
product.Price = 3.99M;
655
-
product.Sizes = new string[] { "Small", "Medium", "Large" };
Convert all serialization code in this #solution from Newtonsoft.Json to System.Text.Json, using the recommended approach for my current .NET version.
650
+
- Update attributes and properties, including rules for skipping or renaming during serialization
651
+
- Ensure polymorphic serialization continues to work correctly
652
+
- Respect existing custom converters and project-level settings (for example, from the Utilities folder or appsettings.json)
653
+
- Update related unit tests and highlight any potential breaking changes
654
+
- Generate a migration summary
659
655
```
660
656
661
-
GitHub Copilot is powered by AI, so surprises and mistakes are possible. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).
657
+
Review Copilot's suggestions before applying. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).
0 commit comments