A complete JSON minifier that takes a formatted string and removes all non-essential whitespace.
ID: 1383
using uCalcSoftware;
var uc = new uCalc();
using (var t = new uCalc.Transformer()) {
// 1. Define rules to remove whitespace and newlines.
// The engine's default QuoteSensitive=true ensures whitespace inside strings is protected.
t.FromTo("{@Whitespace}", "");
t.FromTo("{@Newline}", "");
// 2. Define the formatted input string.
var formattedJson = """
{
"id": 123,
"name": "Example, with spaces",
"tags": [
"A",
"B"
]
}
""";
// 3. Run the transformation and print the result.
Console.WriteLine(t.Transform(formattedJson));
}
{"id":123,"name":"Example, with spaces","tags":["A","B"]} using uCalcSoftware; var uc = new uCalc(); using (var t = new uCalc.Transformer()) { // 1. Define rules to remove whitespace and newlines. // The engine's default QuoteSensitive=true ensures whitespace inside strings is protected. t.FromTo("{@Whitespace}", ""); t.FromTo("{@Newline}", ""); // 2. Define the formatted input string. var formattedJson = """ { "id": 123, "name": "Example, with spaces", "tags": [ "A", "B" ] } """; // 3. Run the transformation and print the result. Console.WriteLine(t.Transform(formattedJson)); }
#include
#include "uCalc.h"
using namespace std;
using namespace uCalcSoftware;
int main() {
uCalc uc;
{
uCalc::Transformer t;
t.Owned(); // Causes t to be released when it goes out of scope
// 1. Define rules to remove whitespace and newlines.
// The engine's default QuoteSensitive=true ensures whitespace inside strings is protected.
t.FromTo("{@Whitespace}", "");
t.FromTo("{@Newline}", "");
// 2. Define the formatted input string.
auto formattedJson = R"({
"id": 123,
"name": "Example, with spaces",
"tags": [
"A",
"B"
]
})";
// 3. Run the transformation and print the result.
cout << t.Transform(formattedJson) << endl;
}
}
{"id":123,"name":"Example, with spaces","tags":["A","B"]} #include <iostream> #include "uCalc.h" using namespace std; using namespace uCalcSoftware; int main() { uCalc uc; { uCalc::Transformer t; t.Owned(); // Causes t to be released when it goes out of scope // 1. Define rules to remove whitespace and newlines. // The engine's default QuoteSensitive=true ensures whitespace inside strings is protected. t.FromTo("{@Whitespace}", ""); t.FromTo("{@Newline}", ""); // 2. Define the formatted input string. auto formattedJson = R"({ "id": 123, "name": "Example, with spaces", "tags": [ "A", "B" ] })"; // 3. Run the transformation and print the result. cout << t.Transform(formattedJson) << endl; } }
Imports System
Imports uCalcSoftware
Public Module Program
Public Sub Main()
Dim uc As New uCalc()
Using t As New uCalc.Transformer()
'// 1. Define rules to remove whitespace and newlines.
'// The engine's default QuoteSensitive=true ensures whitespace inside strings is protected.
t.FromTo("{@Whitespace}", "")
t.FromTo("{@Newline}", "")
'// 2. Define the formatted input string.
Dim formattedJson = "{
""id"": 123,
""name"": ""Example, with spaces"",
""tags"": [
""A"",
""B""
]
}"
'// 3. Run the transformation and print the result.
Console.WriteLine(t.Transform(formattedJson))
End Using
End Sub
End Module
{"id":123,"name":"Example, with spaces","tags":["A","B"]} Imports System Imports uCalcSoftware Public Module Program Public Sub Main() Dim uc As New uCalc() Using t As New uCalc.Transformer() '// 1. Define rules to remove whitespace and newlines. '// The engine's default QuoteSensitive=true ensures whitespace inside strings is protected. t.FromTo("{@Whitespace}", "") t.FromTo("{@Newline}", "") '// 2. Define the formatted input string. Dim formattedJson = "{ ""id"": 123, ""name"": ""Example, with spaces"", ""tags"": [ ""A"", ""B"" ] }" '// 3. Run the transformation and print the result. Console.WriteLine(t.Transform(formattedJson)) End Using End Sub End Module