Newtonsoft.Json.Interface 10.0.0

dotnet add package Newtonsoft.Json.Interface --version 10.0.0
                    
NuGet\Install-Package Newtonsoft.Json.Interface -Version 10.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Newtonsoft.Json.Interface" Version="10.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Newtonsoft.Json.Interface" Version="10.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Newtonsoft.Json.Interface" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Newtonsoft.Json.Interface --version 10.0.0
                    
#r "nuget: Newtonsoft.Json.Interface, 10.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Newtonsoft.Json.Interface@10.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Newtonsoft.Json.Interface&version=10.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Newtonsoft.Json.Interface&version=10.0.0
                    
Install as a Cake Tool

GitHub Workflow Status (with branch)

Nuget Nuget

Newtonsoft.Json.Interface

The Json.NET Interface Converter/Mapper is a JsonConverter attribute that allows interfaces to be mapped to concrete implementations of those interfaces for use when deserializing an object.

This is useful when retrieving objects from a container that does not have access to the concrete implementation, but those objects need to be serialized and deserialized using he interface.

Using the attribute

Place the attribute over the interface definition and specify the class to be used for deserialization.

Basic Usage

Model Conversion

Place an attribute over the interface to define the concrete class to use when deserializing objects with the given interface.

/// <summary>
/// Specifies that the an object serialized as IUser should be
/// deserialized into an instance of User.
/// </summary>
[JsonConverter(typeof(InterfaceToConcreteConverter<IUser, User>))]
public interface IUser : IUser<string>
{

Model Property Conversion

Place an attribute over a model property that uses an interface as the type as shown below.

public class TestPropertyModel
{
    public int Id { get; set; }
    public string Comment { get; set; }

    [JsonConverter(typeof(ConcreteConverter<TestModel>))]
    public ITestModel Model { get; set; }
}

Example

Model Conversion

This example shows how to use the attribute on an interface to direct deserialization to a specific model or entity.

Define an interface as shown below.

public interface IMyModel
{
	string Description { get; set; }
	int Id { get; set; }
	string Name { get; set; }
}

Create a concrete implementation for the interface.

public class MyModel : IMyModel
{
	public int Id { get; set; }
	public string Name { get; set; }
	public string Description { get; set; }
}

Create an array of objects using the interface and then serialize the array to a JSON string.

IMyModel[] models = new MyModel[]
{
	new MyModel()
	{
		Id = 1,
		Name = "Model 1",
		Description = "My new model 1."
	},
	new MyModel()
	{
		Id = 2,
		Name = "Model 2",
		Description = "My new model 2."
	},
	new MyModel()
	{
		Id = 3,
		Name = "Model 3",
		Description = "My new model 3."
	},
};

string json = JsonConvert.SerializeObject(models);

An attempt to deserialize the above array without the attribute would result in the error shown below.

alternate text is missing from this package README image

Now go back and add the attribute to the interface definition.

[JsonConverter(typeof(InterfaceToConcreteConverter<IMyModel, MyModel>))]
public interface IMyModel
{
	string Description { get; set; }
	int Id { get; set; }
	string Name { get; set; }
}

With the attribute on the the interface, the below code would run perfectly. Note that the interface is used in the call to JsonConvert.DeserializeObject and not the concrete class reference.

// ***
// *** Deserialize the items as a list of interfaces.
// ***
IEnumerable<IMyModel> deserializedItems = JsonConvert.DeserializeObject<IEnumerable<IMyModel>>(json);
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
10.0.0 587 11/15/2025
9.0.0 4,331 6/7/2025
8.0.1 46,116 11/25/2023
8.0.0 252 11/25/2023
2.2.3 31,129 7/9/2022
2.2.2 24,662 6/6/2020
2.2.1 796 6/4/2020
2.2.0 736 6/2/2020
2.1.0 892 1/25/2020
1.0.0 1,791 12/15/2014