minify

fnbool minify(out string output, const(char)[] input, out Json5Error err) @safe

Minify JSON5 text by removing comments and optional whitespace.

This function preserves the original token spellings (numbers, string quotes, identifier keys) by using the lexer and re-emitting the original token slices.

Examples

import ddn.data.json5 : minify, Json5Error;

string outp;
Json5Error err;
// Note: avoid block-comment markers in DDoc examples (they can terminate DDoc blocks).
assert(minify(outp, "{ a: 1, //c\n b: 2, }", err));
assert(outp == "{a:1,b:2,}");

Returns

true on success; false with err populated on lexical failure.
fnstring minify(const(char)[] input) @safe

Convenience overload that returns minified JSON5 text.

Note

returns string.init on failure.