Schema.NET 13.0.0

This package has a SemVer 2.0.0 package version: 13.0.0+build.1303.
dotnet add package Schema.NET --version 13.0.0                
NuGet\Install-Package Schema.NET -Version 13.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="Schema.NET" Version="13.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Schema.NET --version 13.0.0                
#r "nuget: Schema.NET, 13.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.
// Install Schema.NET as a Cake Addin
#addin nuget:?package=Schema.NET&version=13.0.0

// Install Schema.NET as a Cake Tool
#tool nuget:?package=Schema.NET&version=13.0.0                

Schema.NET Banner

Schema.NET NuGet Package Schema.NET Azure Artifacts Package Schema.NET NuGet Package Downloads Twitter URL Twitter Follow

Schema.org objects turned into strongly typed C# POCO classes for use in .NET. All classes can be serialized into JSON/JSON-LD and XML, typically used to represent structured data in the head section of html page.

Simple Example

var website = new WebSite()
{
    AlternateName = "An Alternative Name",
    Name = "Your Site Name",
    Url = new Uri("https://example.com")
};
var jsonLd = website.ToString();

The code above outputs the following JSON-LD:

{
    "@context":"https://schema.org",
    "@type":"WebSite",
    "alternateName":"An Alternative Name",
    "name":"Your Site Name",
    "url":"https://example.com"
}

If writing the result into a <script> element, be sure to use the .ToHtmlEscapedString() method instead to avoid exposing your website to a Cross-Site Scripting attack. See the example below.

What is Schema.org?

schema.org defines a set of standard classes and their properties for objects and services in the real world. This machine readable format is a common standard used across the web for describing things.

Where is Schema.org Used?

Websites

Websites can define Structured Data in the head section of their html to enable search engines to show richer information in their search results. Here is an example of how Google can display extended metadata about your site in it's search results.

Google Logo Structured Data Example

Using structured data in html requires the use of a script tag with a MIME type of application/ld+json like so:

<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Organization",
  "url": "https://www.example.com",
  "name": "Unlimited Ball Bearings Corp.",
  "contactPoint": {
    "@type": "ContactPoint",
    "telephone": "+1-401-555-1212",
    "contactType": "Customer service"
  }
}
</script>
Important Security Notice

When serializing the result for a website's <script> tag, you should use the alternate .ToHtmlEscapedString() to avoid exposing yourself to a Cross-Site Scripting (XSS) vulnerability if some of the properties in your schema have been set from untrusted sources. Usage in an ASP.NET MVC project might look like this:

<script type="application/ld+json">
    @Html.Raw(Model.Schema.ToHtmlEscapedString())
</script>
Windows UWP Sharing

Windows UWP apps let you share data using schema.org classes. Here is an example showing how to share metadata about a book.

Classes & Properties

schema.org defines classes and properties, where each property can have a single value or an array of multiple values. Additionally, properties can have multiple types e.g. an Address property could have a type of string or a type of PostalAddress which has it's own properties such as StreetAddress or PostalCode which breaks up an address into it's constituent parts.

To facilitate this Schema.NET uses some clever C# generics and implicit type conversions so that setting a single or multiple values is possible and that setting a string or PostalAddress is also possible:

// Single string address
var organization = new Organization()
{
    Address = "123 Old Kent Road E10 6RL"
};

// Multiple string addresses
var organization = new Organization()
{
    Address = new List<string>()
    { 
        "123 Old Kent Road E10 6RL",
        "456 Finsbury Park Road SW1 2JS"
    }
};

// Single PostalAddress address
var organization = new Organization()
{
    Address = new PostalAddress()
    {
        StreetAddress = "123 Old Kent Road",
        PostalCode = "E10 6RL"
    }
};

// Multiple PostalAddress addresses
var organization = new Organization()
{
    Address = new List<PostalAddress>()
    {
        new PostalAddress()
        {
            StreetAddress = "123 Old Kent Road",
            PostalCode = "E10 6RL"
        },
        new PostalAddress()
        {
            StreetAddress = "456 Finsbury Park Road",
            PostalCode = "SW1 2JS"
        }
    }
};

// Mixed Author types
var book = new Book()
{
    Author = new List<object>()
    {
        new Organization() { Name = "Penguin" },
        new Person() { Name = "J.D. Salinger" }
    }
};

// Deconstruct a property containing mixed types
if (book.Author.HasValue)
{
    var (organisations, people) = book.Author.Value;
}

This magic is all carried out using implicit conversion operators in the OneOrMany<T>, Values<T1, T2>, Values<T1, T2, T3> and Values<T1, T2, T3, T4> types. These types are all structs for best performance too.

More Examples

For more examples and actual running code samples, take a look at the unit tests in the project source code.

Schema.NET.Pending

There are many pending types on schema.org which are not yet fully formed and ready for production. If you need to use these, you can install the Schema.NET.Pending NuGet package instead of Schema.NET. This package contains all released schema types as well as all pending types.

Schema.NET.Pending NuGet Package Schema.NET.Pending Azure Artifacts Package Schema.NET.Pending NuGet Package Downloads

Continuous Integration

Name Operating System Status History
Azure Pipelines Ubuntu Azure Pipelines Ubuntu Build Status
Azure Pipelines Mac Azure Pipelines Mac Build Status
Azure Pipelines Windows Azure Pipelines Windows Build Status
Azure Pipelines Overall Azure Pipelines Overall Build Status Azure DevOps Build History
GitHub Actions Ubuntu, Mac & Windows GitHub Actions Status GitHub Actions Build History
AppVeyor Ubuntu, Mac & Windows AppVeyor Build Status AppVeyor Build History

Contributions and Thanks

Please view the contributing guide for more information.

  • kirkone - CI reads .NET Core version from new global.json file.
  • Turnerj - Added System.Text.Json support, Had all types implement IEquatable<T> GetHashCode and added extra unit tests and bug fixes.
  • shervinw - Added better null value handling for structs.
  • kirk-marple - Refactoring JSON serialization to be more efficient.
  • nickevansuk - Adding better null value handling and use HTTPS instead of HTTP.
  • MEmanuelsson - Added support for the schema.org Date type without time.
  • halovanic - For adding interfaces to Schema.NET types for greater flexibility.
  • AndreSteenbergen - For enabling the tool to work on linux.
  • benmccallum - For adding XSS vlnerability protection.
  • psampaio - Added deserialization support and unit tests.
  • icunningham88 - Improved a test.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (14)

Showing the top 5 NuGet packages that depend on Schema.NET:

Package Downloads
OpenActive.NET

OpenActive.io objects turned into strongly typed C# POCO classes for use in .NET. All classes can be serialized into JSON/JSON-LD, to provide easy conformance with the OpenActive Modelling Specification.

Spin

Web Framework cross platforms based to .net core

DeploySoftware.LaunchPad.Organizations

Organization-related code for LaunchPad framework.

DeploySoftware.LaunchPad.Shared

Shared code for LaunchPad framework.

UmbCheckout.Core

An eCommerce solution for Umbraco

GitHub repositories (2)

Showing the top 2 popular GitHub repositories that depend on Schema.NET:

Repository Stars
mjebrahimi/SeoTags
🚀 SeoTags generates All SEO Tags you need such as meta, link, Twitter card (twitter:), Open Graph (for Facebook) (og:), and JSON-LD schema (structured data).
episerver/Foundation
Foundation offers a starting point that is intuitive, well-structured and modular allowing developers to explore CMS, Commerce, Personalization, Search and Navigation, Data Platform and Experimentation.
Version Downloads Last updated
13.0.0 177,601 12/17/2023
12.0.0 295,164 5/10/2023
11.0.1 400,823 2/22/2022
11.0.0 131,914 11/9/2021
10.1.0 39,156 10/11/2021
10.0.0 108,725 6/25/2021
9.0.0 19,500 4/4/2021
8.0.0 207,887 11/2/2020
7.2.0 74,520 8/21/2020
7.1.0 146,391 3/18/2020
7.0.1 122,820 1/15/2020
7.0.0 6,711 12/31/2019
6.0.0 185,083 10/23/2019
5.0.0 5,677 9/29/2019
4.3.0 16,532 7/1/2019
4.2.0 18,149 6/2/2019
4.1.0 5,451 5/31/2019
4.0.0 935 5/27/2019
3.7.1 22,941 4/25/2019
3.7.0 1,667 4/23/2019
3.6.0 56,458 12/24/2018
3.5.0 82,956 10/19/2018
3.4.0 112,570 2/20/2018
3.2.4 23,783 7/2/2017
3.2.3 1,100 6/19/2017
3.2.2 1,004 6/15/2017
3.2.1 1,049 6/11/2017
3.2.0 1,978 6/8/2017