System.Text.Json or Newtonsoft.Json?
System.Text.Json or Newtonsoft.Json?
A: System.Text.Json (STJ)
Reasons: faster because of usage of spans *1*, less memory used *1*, avoid a 3rd party package, more integration with built in libraries such as HTTPClient with methods such PostAsJsonAsync and ReadFromJsonAsync *2*, using new features such as Minimal APIs *2*
Exceptions: polymorphic serialization in certain situations *2* and jsonpath *2*
Trivia: case insensitive deserialization - turn on if required in STJ see *3* . By default, it is off.
Sources:
*1* = https://trevormccubbin.medium.com/net-performance-analysis-newtonsoft-json-vs-system-text-json-in-net-8-34520c21d054
*2* = https://www.reddit.com/r/dotnet/comments/14xgfjl/should_you_use_newtonsoftjson_or_systemtextjson/
*2* = https://www.reddit.com/r/dotnet/comments/14xgfjl/should_you_use_newtonsoftjson_or_systemtextjson/
*3* = https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonserializerdefaults?view=net-7.0
Comments
Post a Comment