using uCalcSoftware; var uc = new uCalc(); using (var t = new uCalc.Transformer(uc)) { // 1. Define state variable in the uCalc instance. uc.DefineVariable("indent = 0"); // 2. Define the transformation rules. // Note: '{', '}', '[', ']' are escaped with quotes to be treated as literals. // Rule for '{' and '[': Add newline, increment indent, add indent string. t.FromTo("{ '{' | '[' }", "{@Self}{@nl}{@Exec: indent++}{@Eval: ' ' * indent}"); // Rule for '}' and ']': Add newline, decrement indent, add indent string. t.FromTo("{ '}' | ']' }", "{@nl}{@Exec: indent--}{@Eval: ' ' * indent}{@Self}"); // Rule for ',': Add newline and current indent string. t.FromTo(",", ",{@nl}{@Eval: ' ' * indent}"); // Rule for ':': Add a space after it for readability. t.FromTo(":", ": "); // 3. Define the minified input string. var minifiedJson = """ {"id":123,"name":"Example","tags":["A","B"],"active":true} """; // 4. Run the transformation and print the result. Console.WriteLine(t.Transform(minifiedJson)); }