microsoft / microsoft/component-detection

Migrate from `Newtonsoft.Json` to `System.Text.Json`

Open
#231 3 comments 0 reactions 0 assignees View on GitHub
status:ready type:refactor
Dominant language
C#
Stars
553
Forks
135
Avg merge
20h 58m
Merged PRs (30d)
6

Description

For a long time `Newtonsoft.Json` was the best JSON library for .NET. However, since `System.Text.Json` was added in .NET Core 3.0, it's clearly the future. It's a core part of .NET, so there's no need for an additional dependency, and it's far more performant than `Newtonsoft.Json`

A couple of things to be aware of:
- Should we explicitly add [`JsonPropertName` attributes][3] to object properties?
- Should we standardize on [Camel Case][4] (`exampleVariableName`) over [PascalCase][5] (`ExampleVariableName`)?
- Currently we use a mix of both
- `Newtonsoft.Json` can accept both by default, can `System.Text.Json` too?
- Migrate to asynchronous methods instead of synchronous?
- [`SerializeAsync`][6]
- [`DeserializeAsync`][7]

References:
- [`Newtonsoft.Json` to `System.Text.Json` migration guide][1]
- [What's next for `System.Text.Json`][2]

[1]: https://docs.microsoft.com/en-us/dotnet/standard/serialization/system-text-json-migrate-from-newtonsoft-how-to?pivots=dotnet-6-0
[2]: https://devblogs.microsoft.com/dotnet/whats-next-for-system-text-json/
[3]: https://docs.microsoft.com/en-us/dotnet/api/system.text.json.serialization.jsonpropertynameattribute?view=net-6.0
[4]: https://en.wikipedia.org/wiki/Camel_case
[5]: https://en.wiktionary.org/wiki/Pascal_case
[6]: https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializer.serializeasync?view=netcore-3.1
[7]: https://docs.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializer.deserializeasync?view=netcore-3.1

Contributor guide

Open the contributing guide

Research direction

The issue names no files, tests, or entry points; start by inventorying the repository's Newtonsoft.Json usage and reading the linked System.Text.Json migration guide. Resolve the open decisions about property naming, attributes, compatibility, and asynchronous APIs, then verify that all serialization behavior and dependency usage have been migrated.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
devtools
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.