microsoft/migrating-newtonsoft-to-system-text-json
> Migrates .NET projects from Newtonsoft.Json to System.Text.Json, updating package references, code files, and handling API differences. Use when asked to "migrate Newtonsoft", "switch to System.Text.Json", "replace Newtonsoft.Json", or "upgrade JSON library". Triggers for .csproj/.vbproj files referencing Newtonsoft.Json and .cs/.vb files using Newtonsoft.Json namespaces. Also applies when modernizing .NET dependencies or removing third-party JSON libraries.
npx skills add https://github.com/microsoft/upgrade-agent-plugins --skill migrating-newtonsoft-to-system-text-json
Migrate .NET projects from Newtonsoft.Json to System.Text.Json, including package references, code files, and configuration changes while preserving application behavior.
Newtonsoft.Json.Complete all steps in order without pausing between them. Continue until the migration is finished or user input is genuinely required. Ordering matters because later steps depend on earlier ones (e.g., code updates rely on package references being correct first).
Migration Progress:
- [ ] Step 1: Update package dependencies
- [ ] Step 2: Update code files
- [ ] Step 3: Validate migration
- [ ] Step 4: Build verification
For each project with an explicit dependency on Newtonsoft.Json in the project file or imported MSBuild targets (skip projects that only receive it transitively to avoid adding unnecessary new package references):
Newtonsoft.Json package reference and assembly reference from the project file.System.Text.Json package reference with a version supporting the project's target framework. Use tools to determine the best version; fall back to manual determination if unavailable.Newtonsoft.Json PackageVersion entry from Directory.Packages.props.System.Text.Json PackageReference without a version in project files.System.Text.Json PackageVersion entry to Directory.Packages.props.Update code files in affected projects and projects that depend on them (transitive dependents may use Newtonsoft.Json types received through project references):
Newtonsoft.Json — prefer search tools when available, passing root folders for all affected projects.Newtonsoft.Json API usage with System.Text.Json equivalents. Preserve business logic, comments, and formatting. Never add placeholder code.Newtonsoft.Json usings with appropriate System.Text.Json usings.System.Text.Json usings.Newtonsoft.Json usings existed originally, do not add System.Text.Json usings.JsonPropertyAttribute with JsonPropertyNameAttribute requires using System.Text.Json.Serialization; because the type moved from the root namespace to a child namespace.Search all affected projects for any remaining Newtonsoft.Json references. If any are found, return to Step 2. Repeat until no references remain. This loop catches references missed in large solutions where transitive dependencies can hide usages.
Build all modified projects. Fix all build errors before proceeding — iterating until the build succeeds ensures the migration is mechanically correct.
| Behavior | Newtonsoft.Json | System.Text.Json |
|----------|----------------|------------------|
| Property name matching | Case-insensitive by default | Case-sensitive by default — use PropertyNameCaseInsensitive if needed |
| Character escaping | Permissive | Escapes more characters for XSS protection |
| Comments/trailing commas | Allowed by default | Requires ReadCommentHandling and AllowTrailingCommas |
| Numbers in quotes | Accepted | Requires NumberHandling configuration |
| Quote style | Single quotes and unquoted names allowed | Requires double quotes per RFC 8259 |
| Newtonsoft.Json | System.Text.Json |
|-----------------|------------------|
| JsonPropertyAttribute | JsonPropertyNameAttribute (in System.Text.Json.Serialization) |
| NullValueHandling.Ignore | DefaultIgnoreCondition global option |
| [JsonConstructor] | [JsonConstructor] (same attribute exists) |
| PreserveReferencesHandling | ReferenceHandler global setting |
| TypeNameHandling | JsonDerivedTypeAttribute for polymorphism |
| JsonConvert.SerializeObject() | JsonSerializer.Serialize() |
| JsonConvert.DeserializeObject() | JsonSerializer.Deserialize() |
System.Text.Json is included in:
Newtonsoft.Json references remain in affected projectsTake microsoft/migrating-newtonsoft-to-system-text-json from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.