Use a package

This tutorial walks you through installing and using the popular Newtonsoft.Json package in a Universal Windows Platform (UWP) project. You use a similar same workflow for virtually every NuGet package you use in a project.


Start with Installing packages from is a common workflow that .NET developers use to find components they can reuse in their own applications. You can always search directly or find and install packages within Visual Studio as shown in this topic.

Install pre-requisites

This tutorial requires Visual Studio 2015 Update 3 with Tools for Universal Windows Apps, or Visual Studio 2017 with the Universal Windows Platform development workload. If you already have Visual Studio installed, you can run the installer again to add the UWP tools.

You can install the Community edition for free from or use the Professional or Enterprise editions.

Create a UWP project

In Visual Studio, choose File > New > Project, expand Visual C# > Windows > Universal, select the Blank App (Universal Windows), and click OK. Accept the default values for Target Version and Minimum Version when prompted.

Creating a new UWP project

Add the Newtonsoft.Json NuGet package

  1. In Solution Explorer, right click on References and choose Manage NuGet Packages.

    Manage NuGet Packages command for project References

  2. Choose "" as the Package source, click the Browse tab, search for Newtonsoft.Json, select that package in the list, and click Install:

    Locating Newtonsoft.Json package

  3. If prompted to review changes, click OK.

  4. Right-click the solution in Solution Explorer and click Build Solution. This restores any NuGet packages listed under References. For more details, see Package Restore.

Use the Newtonsoft.Json API in the app

With the Newtonsoft.Json package in the project, you can call its JsonConvert.SerializeObject method to convert an object to a human-readable string.

  1. Open MainPage.xaml and replace the existing Grid element with the following:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <StackPanel VerticalAlignment="Center">
            <Button Click="Button_Click" Content="Click Me" Margin="10"/>
            <TextBlock Name="TextBlock" Text="TextBlock" Margin="10"/>
  2. Expand the MainPage.xaml node in Solution Explorer, open MainPage.xaml.cs, and insert the following code inside the MainPage class, after the constructor:

    public class Account
        public string Name { get; set; }
        public string Email { get; set; }
        public DateTime DOB { get; set; }
    private void Button_Click(object sender, RoutedEventArgs e)
        Account account = new Account
            Name = "John Doe",
            Email = "",
            DOB = new DateTime(1980, 2, 20, 0, 0, 0, DateTimeKind.Utc),
        string json = JsonConvert.SerializeObject(account, Formatting.Indented);
        TextBlock.Text = json;
  3. Even though you added the Newtonsoft.Json package to the project, you'll still see a red squiggle under JsonConvert because you need a using statement. Hover over the underlined JsonConvert and you'll see the Lightbulb and the option to Show potential fixes:

    Lightbulb with show potential fixes command

  4. Click on Show potential fixes (or the Lightbulb) and select the first suggested fix, using Newtonsoft.Json;. This adds the necessary line to the top of the file.

    Lightbulb giving option to add a using statement

  5. Build and run the app by pressing F5 or selecting Debug > Start Debugging:

    Initial output of the app

  6. Click on the button to see the contents of the TextBlock replaced with some JSON text:

    Output of the app after clicking the button