Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: "Migrate from Newtonsoft.Json to System.Text.Json - .NET"
description: "Learn about the differences between Newtonsoft.Json and System.Text.Json and how to migrate to System.Text.Json."
no-loc: [System.Text.Json, Newtonsoft.Json]
ms.date: 02/11/2025
ms.date: 10/03/2025
helpviewer_keywords:
- "JSON serialization"
- "serializing objects"
Expand All @@ -24,7 +24,7 @@ The `System.Text.Json` namespace provides functionality for serializing to and d
* .NET Core 2.0, 2.1, and 2.2

> [!TIP]
> You can use AI assistance to [migrate from `Newtonsoft.Json`](#use-ai-to-migrate).
> You can use AI assistance to [migrate from `Newtonsoft.Json`](#use-ai-for-solution-wide-migration).

`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.

Expand Down Expand Up @@ -639,26 +639,22 @@ System.Text.Json sets limits that can't be changed for some values, such as the

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).

## Use AI to migrate
## Use AI for solution-wide migration

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.
You can use AI tools, such as GitHub Copilot, to help with migrating your solution code from `Newtonsoft.Json` to `System.Text.Json`.

**Example prompt for Copilot Chat**
Here's an example prompt you can use in Visual Studio Copilot Chat to migrate a solution.

```copilot-prompt
convert the following code to use System.Text.Json
Product product = new Product();

product.Name = "Apple";
product.ExpiryDate = new DateTime(2024, 08, 08);
product.Price = 3.99M;
product.Sizes = new string[] { "Small", "Medium", "Large" };

string output = JsonConvert.SerializeObject(product);
Console.WriteLine(output);
Convert all serialization code in this #solution from Newtonsoft.Json to System.Text.Json, using the recommended approach for my current .NET version.
- Update attributes and properties, including rules for skipping or renaming during serialization
- Ensure polymorphic serialization continues to work correctly
- Respect existing custom converters and project-level settings (for example, from the Utilities folder or appsettings.json)
- Update related unit tests and highlight any potential breaking changes
- Generate a migration summary
```

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).
Review Copilot's suggestions before applying. For more information, see [Copilot FAQs](https://aka.ms/copilot-general-use-faqs).

## Additional resources

Expand Down