Convert Unicorn Serialization configs into Sitecore Content Serialization module JSON with PowerShell

Árvai Mihály
2 min readOct 2, 2020

--

Hi, Today I’m bringing a simple PowerShell which helps you to convert simple Unicorn serialization configuration files into module JSON files.

Sitecore Content Serialization is a new feature which was introduced in Sitecore 10.

Image from: https://doc.sitecore.com/developers/100/developer-tools/en/sitecore-content-serialization.html

If you want to switch a project to this new serialization way and your project has many features and foundation projects with different serialization configurations, it may take time to convert them manually into the new module JSON format. This happened with me, so instead of doing manually, I created a simple PowerShell script which finds every *Serialization.config in a project, and creates the equivalent JSON module file.

The script only supports the following simple unicorn configurations:

  • Simple Item Predicate
<include name="Templates" database="master" path="/sitecore/templates/Foundation/Indexing" />
  • Item Predicate with exclude children=true
<include name="Foundation.Serialization.Settings.Feature" database="master" path="/sitecore/system/Settings/Feature">
<exclude children="true" />
</include>

Roles, users, other exclude options are not supported yet, so please feel free to extend it.

The script

The script is pretty simple. You have to set the $rootFolder variable in the script file and run it. It will take every serialization config in the target folder and place the equivalent module JSON next to the existing Unicorn configuration file. (See below a sample converted file)

e.g we have the following serialization file:

The scripts will set the namespace and references properties based on configuration name and dependencies attributes. It will populate the includes array based on the <includes /> tags. It will append the scope:SingleItem property where <exclude children=”true”/> is defined in the Unicorn configuration files.

--

--