Skip to content

Your first transformer

A Jolt transformation has three parts: a source document (the JSON you have), a transformer (JSON describing what you want), and the output Jolt produces.

transformer.json
{
"name": "#valueOf($.customer.firstName) + ' ' + #valueOf($.customer.lastName)",
"isActive": "#valueOf($.customer.status) == 'active'",
"tagCount": "#valueOf($.customer.tags)->#length()"
}

Each string containing an expression is evaluated against the source document. $.customer.firstName is a JSON Path into the source.

These examples use Jolt.Json.Newtonsoft; the Jolt.Json.DotNet API has the same shape.

using Jolt.Json.Newtonsoft;
public string Run(string transformerJson, string sourceJson)
{
var transformer = JoltJsonTransformer.DefaultWith<TransformerMethods>(transformerJson);
return transformer.Transform(sourceJson);
}

TransformerMethods is the class holding any C# methods your transformer calls. See external methods for how to write and register them.

Given this source document:

source.json
{
"customer": {
"firstName": "Ada",
"lastName": "Lovelace",
"status": "active",
"tags": [ "math", "engines" ]
}
}

The transformer produces:

output.json
{
"name": "Ada Lovelace",
"isActive": true,
"tagCount": 2
}

Try this example in the playground →

Before you have a real source document, Validate() reports syntax and structure problems in the transformer itself. See validation.