ddn.data.json5

JSON5 support for DDN — Design and Policy

This module documents the specification scope and type mapping between JSON5 values and ddn.var. The actual parser/writer implementation is introduced in subsequent tasks.

Mapping rules to var:

  • Objects: map to var.Type.OBJECT with string keys and var values.
  • Arrays: map to var.Type.ARRAY with elements converted to var recursively.
  • Strings: map to var.Type.STRING (both single-quoted and double-quoted forms are accepted).
  • Booleans: map to var.Type.BOOL.
  • null: map to var.Type.NULL.
  • Numbers:
  • If the numeric value is integral and fits a 64-bit signed integer, use Type.LONG.
  • Else if the numeric value is integral and non-negative and fits 64-bit unsigned, use Type.ULONG.
  • Otherwise, use Type.DOUBLE and preserve special cases: NaN, Infinity, -Infinity, -0.0.

Writer rules (summary):

  • Keys are unquoted when they are valid JSON5 identifiers; otherwise quoted with minimal escaping.
  • Values are emitted compactly by default; pretty printing is configurable.
  • Deterministic output is achieved by lexicographically sorting object keys by default.

Feature coverage (JSON5):

  • Comments: `//` line and C-style block comments.
  • Trailing commas in arrays/objects.
  • Unquoted keys when identifier-compatible.
  • Single-quoted strings and escape sequences, including line continuations.
  • Numbers with leading `+`, hex (0x...), leading/trailing decimal points, exponents, and special numbers.
  • BOM (UTF‑8) accepted at the beginning of input.

Examples

import ddn.data.json5 : parseJSON5, toJSON5, toJSON, minify, Json5Error;
import ddn.var : var;

Json5Error err;
var v;
assert(parseJSON5(v, "{a:1, b:'x',}", err));
assert(v["a"].as!long == 1);

// Minify JSON5 (strip comments/whitespace).
// Note: avoid block-comment markers in DDoc examples (they can terminate DDoc blocks).
auto compact = minify("{ a: 1, //c\n b: 2, }");
assert(compact == "{a:1,b:2,}");

// Write JSON5 vs strict JSON.
auto json5Text = toJSON5(v);        // e.g. "{a:1,b:'x'}"
auto jsonText  = toJSON(v);         // e.g. "{\"a\":1,\"b\":\"x\"}"

Types 23

enumJson5Feature : uint

Feature switches for JSON5 support.

COMMENTS = 1u << 0
TRAILING_COMMAS = 1u << 1
SINGLE_QUOTED_STRINGS = 1u << 2
UNQUOTED_KEYS = 1u << 3
HEX_NUMBERS = 1u << 4
SPECIAL_NUMBERS = 1u << 5
LEADING_PLUS = 1u << 6
LEAD_TAIL_DECIMAL = 1u << 7
LINE_CONTINUATIONS = 1u << 8
BOM_UTF8 = 1u << 9

Policy controlling writer defaults and parser behavior.

Note on Policy Naming:

This struct is named Json5Policy following the convention of format-specific policy structs (JsonPolicy, SdlPolicy). The CfParserConfig struct uses a different naming pattern for historical reasons (it predates the policy naming convention and has additional configuration beyond parsing behavior).

Note on lastKeyWins:

Unlike JsonPolicy which uses a JsonDuplicateKeyPolicy enum with three options (LAST_WINS, FIRST_WINS, ERROR), this struct uses a simple boolean. This is intentional: JSON5 is designed as a more lenient format for human-authored configuration files, where strict duplicate detection (ERROR) is rarely desired. The boolean provides a simpler API for the common case of choosing between first-wins and last-wins semantics. When useStrictJsonParser is enabled, the boolean maps to the corresponding enum value in the underlying JsonPolicy.

Fields
bool preferSignedIntegersPrefer signed integers when a value fits both signed and unsigned.
bool lastKeyWinsDuplicate keys policy: if true, last occurrence wins; if false, first wins. Unlike `JsonPolicy.duplicateKeyPolicy`, this is a boolean because JSON5's lenient nature makes the strict ERROR option ra...
size_t maxDepthMaximum nesting depth allowed during parsing to prevent runaway recursion.
bool sortKeysOnWriteWriter: sort object keys for deterministic output.
bool asciiOnlyWriteWriter: emit only ASCII by escaping non-ASCII code points.
bool useStrictJsonParserWhen true, delegate parsing to `ddn.data.json` for potentially faster strict JSON parsing.
enumJson5ErrorCode : ushort

A non-throwing error report produced by the JSON5 parser/writer.

UNKNOWNUnknown/unspecified error.
TRAILING_CONTENTTrailing non-whitespace/comment content after a complete root value.
UNEXPECTED_TOKENUnexpected token kind for the current parse state.
UNEXPECTED_EOFUnexpected end of input.
INVALID_TOKENTokenization failure (invalid UTF-8, malformed comment, etc.).
INVALID_NUMBERInvalid number literal syntax.
INVALID_STRINGInvalid string literal syntax.
INVALID_ESCAPEInvalid escape sequence in a string literal.
MAX_DEPTH_EXCEEDEDParser recursion limit exceeded.
INVALID_ARGUMENTInvalid argument passed to a helper API.
IO_ERRORI/O error while reading/writing.
Fields
size_t line1-based line number where the error occurred (0 if unknown).
size_t column1-based column number where the error occurred (0 if unknown).
size_t index0-based byte offset into the original input (0 if unknown).
Json5ErrorCode codeMachine-readable error category.
string messageHuman-readable message.
string contextExcerpt of the source around `index` with a caret line, if available.
Constructors
this(size_t line, size_t column, string message, Json5ErrorCode code = Json5ErrorCode.UNKNOWN, size_t index = 0, string context = "")Construct an error report.
enumJson5QuoteStyle : ubyte

Quote style used by the JSON5 writer.

DOUBLEEmit double quoted strings: `"..."`.
SINGLEEmit single quoted strings: `'...'`.
enumJson5WriteMode : ubyte

Output mode for the writer.

JSON5Emit JSON5 (allows unquoted keys, single quotes, NaN/Infinity, etc.).
JSONEmit strict JSON (RFC 8259 style).

Writer formatting options for JSON5 emission.

Fields:

  • pretty: enable multi-line pretty printing with indentation.
  • indentWidth: number of spaces per indentation level (used only when pretty).
  • quoteStyle: whether strings are emitted with single or double quotes.
  • asciiOnly: when true, escape non-ASCII as \uXXXX or \u{...}.
  • sortKeys: when true, object keys are emitted sorted for deterministic output.
  • maxDepth: maximum nesting depth allowed during writing; when exceeded, the writer emits null.
  • trailingCommas: when true, pretty mode emits a trailing comma after the last array element

and the last object property; ignored in compact mode.

Fields
Json5WriteMode writeModeSelect whether to emit JSON5 or strict JSON.
bool prettyPretty-print output with indentation.
uint indentWidthNumber of spaces per indentation level when `pretty` is true.
Json5QuoteStyle quoteStyleString quoting style used by the writer.
Json5FloatFormat floatFormatFloating-point number formatting style.
uint floatPrecisionPrecision parameter for float formatting.
uint scientificExponentThresholdIf `floatFormat == AUTO`, switch to scientific when `abs(exponent) >= threshold`.
bool hexIntegersEmit integer values in hexadecimal form (`0x...`) when true.
Json5NegativeZeroStyle negativeZeroStyleControls how `-0.0` is emitted.
bool asciiOnlyEscape non-ASCII code points as \uXXXX.
bool sortKeysSort object keys for deterministic output.
bool trailingCommasEmit trailing commas in pretty mode for arrays/objects.
size_t maxDepthMaximum nesting depth allowed during writing to prevent runaway recursion.

Reusable scratch buffers for JSON5/JSON writing.

This structure allows caller-controlled reuse of temporary allocations across repeated serializations.

Currently used for:

  • Deterministic object serialization (sortKeys == true) via per-depth key buffers.
Fields
string[][] keyBuffersPer-depth buffers used to collect and sort object keys.
enumJson5FloatFormat : ubyte

Floating-point formatting mode used by the JSON5 writer.

SHORTESTUse the default D `to!string` representation.
FIXEDEmit fixed notation (`%.<precision>f`).
SCIENTIFICEmit scientific notation (`%.<precision>e`).
AUTOChoose between `SHORTEST` and `SCIENTIFIC` based on `scientificExponentThreshold`.

Controls how floating-point negative zero is emitted.

MINUS_ZERO_DOT_ZEROEmit negative zero as `-0.0`.
MINUS_ZEROEmit negative zero as `-0`.
aliasJson5Reviver = var delegate(const string key, var value) @safe

Reviver callback used to transform parsed values.

The callback is invoked in post-order (children first), similarly to JavaScript JSON.parse(text, reviver).

Arguments:

  • key: Object key / array index (as decimal string). Root is passed as `""`.
  • value: Current value.

The return value is the replacement value.

enumJson5PatchOpKind : ubyte

Kind of a JSON5 patch operation.

ADDAdd a value at `path`.
REMOVERemove the value at `path`.
REPLACEReplace the value at `path`.

A single JSON5 patch operation.

The path is a JSON Pointer-like path using `/` separators.

  • Root is `""`.
  • ~1 decodes to `/`.
  • ~0 decodes to `~`.
Fields
Json5PatchOpKind kindOperation kind.
string pathTarget path.
var valueValue for `ADD`/`REPLACE`.

Patch application error.

Fields
size_t opIndexIndex of the failing operation.
string pathPath associated with the failure.
string messageHuman-readable message.
enumJson5StreamResult : ubyte

Result of a streaming JSON5 parse attempt.

NEED_MOREThe parser needs more input to decide.
OKA complete JSON5 value was parsed successfully.
ERRORA syntax or lexical error occurred.

Incremental/streaming JSON5 parser that accepts input in chunks.

This API is intended for large inputs or network streams where the complete document may not be available at once.

Notes:

  • The parser produces at most one root JSON5 value.
  • After a successful parse (Json5StreamResult.OK), the instance becomes done;

call reset() to parse another document.

  • When finish() has not been called yet, parse failures that look like

“unexpected end of input” are reported as NEED_MORE.

Examples

import ddn.data.json5 : Json5StreamParser, Json5StreamResult, Json5Error;
import ddn.var : var;

Json5StreamParser sp;
sp.push("{a:1,");
var v; Json5Error err;
assert(sp.tryParse(v, err) == Json5StreamResult.NEED_MORE);
sp.push("b:2}");
assert(sp.tryParse(v, err) == Json5StreamResult.OK);
assert(v["b"].as!long == 2);
Fields
private string _buffer
private Json5Policy _policy
private bool _finished
private bool _done
Methods
void push(const(char)[] chunk) @safeAppend a new chunk of input to the internal buffer.
void finish() @safeMark the stream as finished.
void reset() @safeReset the parser state and clear all buffered input.
bool done() @property const @safeTrue once a full root value has been successfully parsed.
size_t bufferedLength() @property const @safeCurrent buffered input size in bytes.
Json5StreamResult tryParse(out var value, out Json5Error err) @safeAttempt to parse the buffered data as a single JSON5 root value.
private bool _looksIncomplete(ref Json5Parser p) const @safeHeuristic: detect failures likely caused by an incomplete final chunk.
Constructors
this(const Json5Policy policy)Construct a streaming parser using `policy`.

Callbacks for SAX-style JSON5 parsing.

Any callback may be left null to ignore that event.

Event semantics:

  • onObjectStart / onObjectEnd are emitted for `{` / `}`.
  • onArrayStart / onArrayEnd are emitted for `[` / `]`.
  • onKey is emitted for each object property key, before its value.
  • onValue is emitted for scalar values only (null/bool/number/string).
Fields
void delegate() @safe onObjectStartCalled when an object begins (`{`).
void delegate() @safe onObjectEndCalled when an object ends (`}`).
void delegate() @safe onArrayStartCalled when an array begins (`[`).
void delegate() @safe onArrayEndCalled when an array ends (`]`).
void delegate(const string key) @safe onKeyCalled for each object key.
void delegate(const var value) @safe onValueCalled for each scalar value.
enumJson5TokenKind : ushort

Kinds of JSON5 tokens.

END
LBRACE
RBRACE
LBRACKET
RBRACKET
COLON
COMMA
STRING
IDENTIFIER
NUMBER
TRUE_LIT
FALSE_LIT
NULL_LIT
INF_LIT
NAN_LIT
COMMENT
ERROR

A single JSON5 token.

Fields
Json5TokenKind kindToken kind.
size_t line1-based line on which the token starts.
size_t column1-based column on which the token starts.
const(char)[] lexemeRaw slice of the input covering the token text (for STRING/IDENTIFIER/NUMBER).
size_t startIndexStart index in the source buffer (for reconstruction when `lexeme` is empty).
size_t endIndexEnd index (one past last) in the source buffer.

High-performance JSON5 lexer over a UTF‑8 buffer.

  • Skips BOM, whitespace, and comments.
  • Returns slices for identifiers, strings, and numbers without allocating.
  • Tracks line/column for diagnostics.
Fields
private const(char)[] _src
private size_t _i
private size_t _line
private size_t _col
Methods
size_t line() @property const @safeCurrent 1-based line number.
size_t column() @property const @safeCurrent 1-based column number.
Json5Token nextToken() @safeReturn the next token from the stream.
Json5Token nextTokenWithComments() @safeReturn the next token, emitting COMMENT tokens instead of skipping them.
private void _skipSpaceOnly() @safe
private Json5Token _tok(Json5TokenKind k, size_t start, size_t len) @safe
private void _advanceOne() @safe
private void _skipSpaceAndComments() @safe
private bool _isIdentStartAhead() @safe
private bool _isIdentContinueAhead() @safe
private Json5Token _scanIdentifier() @safe
private Json5Token _scanString() @safe
private Json5Token _scanNumber() @safe
Constructors
this(const(char)[] input)Construct a lexer over `input`.

A small, non-throwing JSON5 recursive-descent parser that builds ddn.var directly.

Create an instance with input and policy, then call parseRoot(out var) to parse a value. On failure, parseRoot returns false and populates the provided Json5Error with line/column and a brief message.

Fields
Json5Lexer lxUnderlying lexer (exposed for diagnostics in tests).
Json5Token curCurrent token (public for testing and the outer wrapper).
size_t _prevEndIndexEnd index of the previously returned token (used for boundary recovery).
Json5Policy policyParser policy (depth limits, preferences, etc.).
private Json5Error * _perrError sink pointer (non-owning).
Methods
void advance() @safeAdvance to the next token.
bool parseRoot(out var v) @safeParse a root value into `out v`.
bool parseValue(out var outv, size_t depth) @safeParse a value at a given depth into `out v`.
bool parseArray(out var outv, size_t depth) @safeParse an array value; assumes `cur` is `[` on entry.
bool parseObject(out var outv, size_t depth) @safeParse an object value; assumes `cur` is `{` on entry.
private string _nearSnippet(size_t context = 30) @safeBuild a context window for diagnostics based on current token.
bool fail(const(char)[] msg, const Json5ErrorCode code = Json5ErrorCode.UNEXPECTED_TOKEN) @safeRecord an error at the current position and return `false`.
private string _tokenName(Json5TokenKind k) @safe pure nothrow @nogc
Constructors
this(const(char)[] input, Json5Policy policy, ref Json5Error err)Construct a parser for `input` with `policy`, using `err` as the error sink.

Internal CDM-producing parser structure that reuses the existing lexer.

This struct is used by parseJson5Cdm to produce CdmDocument instances while preserving comments, source locations, and formatting metadata.

Fields
string source
CdmComment[] pendingComments
Builder builder
Methods
void advance() @safeAdvance to the next token, collecting comments along the way.
CdmComment makeComment(Json5Token tok) @safeCreate a CdmComment from a comment token.
CdmComment[] consumePendingComments() @safeConsume and return all pending comments.
CdmLocation currentLocation() @safeGet the current source location.
bool fail(const(char)[] msg, Json5ErrorCode code = Json5ErrorCode.UNEXPECTED_TOKEN) @safeRecord an error and return false.
Constructors
this(const(char)[] input, Json5Policy policy, Json5Error * err, string source)Construct a CDM parser over `input`.
classJson5Exception : Exception

Parse JSON5 text into a CDM document.

Preserves comments, source locations, and formatting metadata for roundtrip fidelity.

Parameters

inputJSON5 text to parse.
sourceOptional source identifier (file path, URI).

Returns

A CdmDocument containing the parsed structure.

Throws

Json5Exception on parse error.

Example:

import ddn.data.json5;
import ddn.data.cdm;

auto doc = parseJson5Cdm(`{
   // Server configuration
   host: "localhost",
   port: 8080
}`);
assert(doc.root.isObject);
assert(doc.root["host"].as!string == "localhost");

Exception thrown when JSON5 parsing fails.

This exception includes source location information for error reporting.

Fields
size_t lineLine number where the error occurred (1-based)
size_t columnColumn number where the error occurred (1-based)
Constructors
this(string msg, size_t line, size_t column)Construct a Json5Exception.

Functions 71

private fnJson5Error _makeError(const(char)[] src, const size_t line, const size_t column, const size_t index, const Json5ErrorCode code, const string msg) @safeBuild a structured error with a context window.
private fnstring _json5ContextWindow(const(char)[] src, size_t index, size_t context = 30) @safeBuild a context window for diagnostics.
private fnstring[] _scratchKeys(ref Json5WriteScratch scratch, const size_t depth) ref @safeObtain a cleared scratch key buffer for a given writer recursion `depth`.
fnbool parseJSON5(out var value, const(char)[] input, out Json5Error err) @safeParse JSON5 text from `input` into `value`.
fnbool parseJSON5(out var value, const(char)[] input, out Json5Error err, Json5Policy policy) @safeParse JSON5 text into a `var` value with custom policy.
fnbool parseJSON5(out var value, const(char)[] input, Json5Reviver reviver, out Json5Error err) @safeParse JSON5 text and apply `reviver` to each value.
private fnvoid _applyReviver(ref var value, const string key, scope Json5Reviver reviver) @safeApply `reviver` to `value` in post-order.
fnvar parseJSON5(const(char)[] input) @safeConvenience overload that parses JSON5 text and returns the resulting value. Note: returns `var.init` on failure.
fnbool minify(out string output, const(char)[] input, out Json5Error err) @safeMinify JSON5 text by removing comments and optional whitespace.
fnstring minify(const(char)[] input) @safeConvenience overload that returns minified JSON5 text.
fnJson5PatchOp[] json5Diff(var from, var to) @safeCompute a patch transforming `from` into `to`.
fnbool json5Patch(ref var base, scope const Json5PatchOp[] ops, out Json5PatchError err) @safeApply a patch to `base`.
private fnstring[] _jsonPointerSplit(const string path) @safeSplit a JSON Pointer path into decoded segments.
private fnstring _jsonPointerUnescape(const string segment) @safeUnescape a JSON Pointer segment.
private fnvoid _json5DiffInto(ref Json5PatchOp[] ops, var from, var to, const string path) @safe
private fnstring _jsonPointerEscape(const string segment) @safeEscape a JSON Pointer segment.
private fnbool _applyPatchOp(ref var base, ref const Json5PatchOp op, ref Json5PatchError err) @trusted
private fnvoid _ensureContainerForPath(ref var container, const string seg) @safeEnsure `container` is initialized as an object or array to accommodate `seg`.
private fnbool _looksLikeArrayIndex(const string seg) @safe pure nothrow @nogcReturns true if `seg` is a plausible JSON Patch array index.
private fnbool _parseArrayIndex(const string seg, out size_t index, const size_t length, const bool allowEnd = false) @safe pure nothrow @nogc
fnbool parseJSON5(out var value, ref File file, out Json5Error err, const Json5Policy policy = Json5Policy.init, size_t chunkSize = 16_384) @safeParse JSON5 data from an open `std.stdio.File`.
fnbool parseJSON5(R)(out var value, R input, out Json5Error err, const Json5Policy policy = Json5Policy.init, size_t chunkSize = 16_384) if ( isInputRange!R && (is(ElementType!R == ubyte) || isSomeChar!(ElementType!R)) ) @safeParse JSON5 data from an input range of `char` or `ubyte`.
fnbool parseJSON5Sax(const(char)[] input, ref Json5SaxHandler handler, out Json5Error err, const Json5Policy policy = Json5Policy.init) @safeParse JSON5 text and emit SAX-style events into `handler`.
fnstring toJSON5(const var value, const Json5WriteOptions opts = Json5WriteOptions.init) @safeSerialize a `var` to JSON5 text using the provided `opts`.
fnstring toJSON5(const var value, const Json5WriteOptions opts, ref Json5WriteScratch scratch) @safeSerialize a `var` to JSON5 text using the provided `opts` and reusable `scratch` buffers.
fnstring toJSON(const var value, const Json5WriteOptions opts = Json5WriteOptions.init) @safeSerialize a `var` to strict JSON text.
fnstring toJSON(const var value, const Json5WriteOptions opts, ref Json5WriteScratch scratch) @safeSerialize a `var` to strict JSON text using the provided `opts` and reusable `scratch` buffers.
private fnvoid _writeJSON5Impl(const var value, ref Appender!string buf, const Json5WriteOptions opts, uint depth, ref Json5WriteScratch scratch) @safe
private fnvoid _writeInteger(T)(T v, ref Appender!string buf, const Json5WriteOptions opts) @safeWrite a numeric integer value according to `opts`.
private fnvoid _putHexUnsigned(const ulong v, ref Appender!string buf) @safeEmit a hexadecimal unsigned integer with `0x` prefix.
private fnvoid _writeDouble(T)(T d, ref Appender!string buf, const Json5WriteOptions opts) @safeWrite a floating-point value according to `opts`.
private fnvoid _writeJSONString(scope const(char)[] s, ref Appender!string buf, const bool asciiOnly, const Json5QuoteStyle quoteStyle = Json5QuoteStyle.DOUBLE) @safe
private fnvoid _writeKey(const string key, ref Appender!string buf, const Json5WriteOptions opts) @safe
private fnbool _shouldQuoteKey(const(char)[] key, const bool asciiOnly) @safe
private fnvoid _indent(ref Appender!string buf, uint depth, uint indentWidth) @safe
private fnvoid _writePrettyArray(const var[] arr, ref Appender!string buf, const Json5WriteOptions opts, uint depth, ref Json5WriteScratch scratch) @safe
private fnvoid _writePrettyObject(const var[string] obj, const string[] keys, ref Appender!string buf, const Json5WriteOptions opts, uint depth, ref Json5WriteScratch scratch) @safe
fnbool load(out var obj, const string fileName, out Json5Error err) @safeLoad a JSON5 file from disk into `obj`.
fnbool save(const var obj, const string fileName, const Json5WriteOptions opts = Json5WriteOptions.init, out Json5Error err) @safeSave a `var` as JSON5 to disk.
private fnvoid _removeNoThrow(const string fileName) @safeRemove a file, ignoring any exception that may occur.
private fnbool _isJSON5UnicodeWhitespace(const dchar dc) @safe pure nothrow @nogcReturns true if `dc` is a non-ASCII whitespace character recognized by JSON5.
private fnbool _isJSON5UnicodeLineTerminator(const dchar dc) @safe pure nothrow @nogcReturns true if `dc` is a JSON5 Unicode line terminator.
fnbool parseJSON5NumericLiteral(out var value, const(char)[] text, const Json5Policy policy = Json5Policy.init) @safeParse a JSON5 numeric literal from `text` into `out value`.
fnbool parseJSON5StringLiteral(out string result, const(char)[] text, out Json5ErrorCode errCode) @safeDecode a JSON5 string literal (single or double quoted) into a D `string`.
fnbool parseJSON5StringLiteral(out string result, const(char)[] text) @safeDecode a JSON5 string literal.
private fnuint _hexVal(const char h) @safe @nogc pure nothrowConvert a hex digit char to its numeric value (assumes valid hex digit).
private fnbool _isHex(const char h) @safe @nogc pure nothrowCheck if a character is a hexadecimal digit (0-9, a-f, A-F).
private fnvoid _putCodePoint(ref Appender!string buf, uint code) @safeAppend a Unicode code point as UTF‑8 to buffer.
private fnstring decodeIdentifierEscapes(const(char)[] text) @safeDecode Unicode escape sequences (\uXXXX) in an identifier lexeme. Identifiers may contain \uXXXX escapes per JSON5 spec. Returns the decoded string, or the original if no escapes present.
fnbool isValidUnquotedKey(const(char)[] key) @safeCheck whether `key` can be emitted without quotes in JSON5 (valid identifier).
private fnstring extractCommentText(const(char)[] raw) @safeExtract comment text from raw token (strip delimiters)
private fnCdmFormat.QuoteStyle detectQuoteStyle(const(char)[] token) @safe pure nothrow @nogcDetect quote style from string token
private fnCdmFormat.NumberFormat detectNumberFormat(const(char)[] token) @safe pure nothrow @nogcDetect number format from literal
private fnbool parseCdmValue(Builder)(ref Json5CdmParser!Builder p, size_t depth) @safeParse a value via the builder
private fnbool parseCdmNumber(Builder)(ref Builder builder, const(char)[] lexeme, Json5Policy policy) @safeParse a number literal and set it on the builder
private fnbool parseCdmString(Builder)(ref Builder builder, const(char)[] lexeme) @safeParse a string literal and set it on the builder
private fnbool parseCdmObject(Builder)(ref Json5CdmParser!Builder p, CdmComment[] leadingComments, CdmLocation loc, size_t depth) @safeParse an object via the builder
private fnbool parseCdmArray(Builder)(ref Json5CdmParser!Builder p, CdmComment[] leadingComments, CdmLocation loc, size_t depth) @safeParse an array via the builder
fnauto parseJson5Cdm(Builder = CdmBuilder)(const(char)[] input, string source = "") @trustedParse JSON5 text.
fnauto parseJson5Cdm(Builder = CdmBuilder)(File file) @safeParse JSON5 file.
fnbool parseJson5Cdm(out CdmDocument doc, const(char)[] input, Json5Error * err, string source = "", Json5Policy policy = Json5Policy.init) @safeNon-throwing parse variant that produces a `CdmDocument`.
private fnbool parseJson5CdmWithBuilder(Builder)(ref Builder.Result result, const(char)[] input, Json5Error * err, string source = "", Json5Policy policy = Json5Policy.init) @safeInternal templated parse function that works with any builder.
fnstring toJson5(const ref CdmDocument doc, Json5WriteOptions opts = Json5WriteOptions.init) @safeSerialize a CDM document to JSON5 text.
private fnvoid writeCdmNode(Out)(ref Out buf, const ref CdmNode node, uint depth, const ref Json5WriteOptions opts) @safeWrite a CDM node to the output buffer
private fnvoid writeCdmComment(Out)(ref Out buf, const CdmComment c, uint depth, const ref Json5WriteOptions opts) @safeWrite a comment to the output buffer
private fnvoid writeInlineCdmComment(Out)(ref Out buf, const CdmComment c) @safeWrite an inline comment
private fnvoid writeCdmString(Out)(ref Out buf, const(char)[] s, CdmFormat.QuoteStyle style, const ref Json5WriteOptions opts) @safeWrite a string with proper quoting
private fnvoid writeCdmObject(Out)(ref Out buf, const ref CdmNode node, uint depth, const ref Json5WriteOptions opts) @safeWrite an object to the output buffer
private fnvoid writeCdmArray(Out)(ref Out buf, const ref CdmNode node, uint depth, const ref Json5WriteOptions opts) @safeWrite an array to the output buffer
private fnvoid writeCdmValueOnly(Out)(ref Out buf, const ref CdmNode node, uint depth, const ref Json5WriteOptions opts) @safeWrite only the value (without leading comments)
private fnvoid writeCdmKey(Out)(ref Out buf, const(char)[] key, CdmFormat.QuoteStyle style, const ref Json5WriteOptions opts) @safeWrite a key with proper quoting

Variables 1

enumvarJSON5_DEFAULT_FEATURES = cast(uint)( Json5Feature.COMMENTS | Json5Feature.TRAILING_COMMAS | Json5Feature.SINGLE_QUOTED_STRINGS | Json5Feature.UNQUOTED_KEYS | Json5Feature.HEX_NUMBERS | Json5Feature.SPECIAL_NUMBERS | Json5Feature.LEADING_PLUS | Json5Feature.LEAD_TAIL_DECIMAL | Json5Feature.LINE_CONTINUATIONS | Json5Feature.BOM_UTF8)

Default feature set enabled by the JSON5 reader/writer.