JsonTemplates 1.0.0

dotnet add package JsonTemplates --version 1.0.0
                    
NuGet\Install-Package JsonTemplates -Version 1.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="JsonTemplates" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="JsonTemplates" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="JsonTemplates" />
                    
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 JsonTemplates --version 1.0.0
                    
#r "nuget: JsonTemplates, 1.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 JsonTemplates@1.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=JsonTemplates&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=JsonTemplates&version=1.0.0
                    
Install as a Cake Tool

What are JSON Templates?

Json tempaltes are a way to help move boilerplate json into a reusable file. No more duplicated json in variations of config files. Intead push all the basics down a level and just deal with the differences. Its easy!

How?

Similarly to the $schema directives, we can use a $template directive. This uses a relative file path, to find the template. The template is loaded in first, and then the current json is applied in a layer above.

Example

Lets first look at a simple user object with a template

{
  "$template": "..\\templates\\user.json"
  "id": 12402945,
  "email": "some.mail@a.place",
  "isVerified": true,
  "profile": {
    "language": "fr-fr"
  }
}

And then the user template would look like. This template references another template. That template only applies to the scope of profile.

{
  "isVerified": false,
  "isActive": true,
  "profile": {
    "$template": "profile.json",
  }
}

And then the profile template

{
  "language": "en-us",
  "timezone": "UTC+0",
}

Together they merge nicely into a single document when we load the base. Notice the $template properties are dropped. Also values from the templates are replaced by the higher level.

{
  "id": 12402945,
  "email": "some.mail@a.place",
  "isVerified": true,
  "isActive": true,
  "profile": {
    "language": "fr-fr"
    "timezone": "UTC+0",
  }
}

Quick Start

To load a templated json, simply pass the file path into the library like so

using System.Text.Json.Nodes;
using JsonTemplates;

string filePath = "path to your json";
JsonNode? json = JsonTemplate.LoadJson(filePath);
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  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.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.
  • net8.0

    • No dependencies.

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
1.0.0 185 6/20/2025