Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
In this quickstart, you install the popular Newtonsoft.Json NuGet package into a .NET project. NuGet packages contain compiled binary code that developers make available for other developers to use in their projects. For more information, see An introduction to NuGet.
To install the package, you use the dotnet package add command, which is part of the dotnet command-line interface (CLI).
Tip
Browse nuget.org/packages to find packages you can reuse in your own applications. You can search directly at https://nuget.org/packages, or you can find and install packages from within Visual Studio. For more information, see Find and evaluate NuGet packages for your project.
Prerequisites
The .NET SDK, which provides the dotnet CLI. In Visual Studio, the dotnet CLI automatically installs with any .NET-related workloads.
Create a project
You can install NuGet packages into a .NET project. For this quickstart, take the following steps to create a basic .NET console project by using the dotnet CLI:
Create a folder named Nuget.Quickstart for the project.
Open a command prompt window and go to the new folder.
Create the project by using the following command:
dotnet new consoleUse
dotnet runto test the app. The command writes the following output to the screen:Hello, World!.
Add the Newtonsoft.Json NuGet package
Use the following command to install the
Newtonsoft.Jsonpackage:dotnet package add Newtonsoft.JsonIf you're using .NET 9 or earlier, use the verb-first form instead:
dotnet add package Newtonsoft.JsonAfter the command finishes, open the Nuget.Quickstart.csproj file in Visual Studio or in a text editor. Check for the added NuGet package reference:
<ItemGroup> <PackageReference Include="Newtonsoft.Json" Version="13.0.4" /> </ItemGroup>
Use the Newtonsoft.Json API in the app
In code, you refer to installed packages by using a using <namespace> directive, where <namespace> is often the package name. You can then use the package's API in your project.
In Visual Studio or in a text editor, open the Program.cs file. Add the following line to the top of the file:
using Newtonsoft.Json;Add the following code to replace the
Console.WriteLine("Hello, World!");statement:namespace Nuget.Quickstart { public class Account { public string? Id { get; set; } public decimal Balance { get; set; } public DateTime Created { get; set; } } internal class Program { static void Main(string[] args) { Account account = new Account { Id = "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u", Balance = 4389.21m, Created = new DateTime(2026, 4, 16, 0, 0, 0, DateTimeKind.Utc), }; string json = JsonConvert.SerializeObject(account, Formatting.Indented); Console.WriteLine(json); } } }Save the file, and then build and run the app by using the
dotnet runcommand. The output is the JSON representation of theAccountobject in the code:{ "Id": "A1bC2dE3fH4iJ5kL6mN7oP8qR9sT0u", "Balance": 4389.21, "Created": "2026-04-16T00:00:00Z" }
Related videos
For videos about using NuGet for package management, see .NET Package Management with NuGet for Beginners and NuGet for Beginners.
Related content
To find out more about installing and using NuGet packages by using the dotnet CLI, see the following articles: