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.
1. Write a transformer
Section titled “1. Write a transformer”{ "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.
2. Run it from C#
Section titled “2. Run it from C#”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.
3. See the result
Section titled “3. See the result”Given this source document:
{ "customer": { "firstName": "Ada", "lastName": "Lovelace", "status": "active", "tags": [ "math", "engines" ] }}The transformer produces:
{ "name": "Ada Lovelace", "isActive": true, "tagCount": 2}Try this example in the playground →
Check your syntax early
Section titled “Check your syntax early”Before you have a real source document, Validate() reports syntax and structure problems in the transformer itself. See validation.
Where to go next
Section titled “Where to go next”- Syntax covers the rules every expression follows.
- Methods and piping explains
#method()calls and the->operator. - The library reference lists every built-in method.
