JsonParser

class JsonParser(maxDepth: Int = DEFAULT_MAX_JSON_DEPTH)

Parses JSON text straight into the Variant encoding.

The parser reads UTF-8 bytes, not a decoded String, for two reasons that both matter to an ingest path: a string with no escapes is copied into the value byte-for-byte with no decode and no re-encode, and every error carries an exact byte offset into the input the caller handed over.

Input is validated strictly. Malformed UTF-8, unescaped control characters, unpaired surrogate escapes, leading zeros and trailing content are all rejected with a position — an ingest engine that quietly repairs its input is one that stores something the caller never wrote.

val variant = Variant.fromJson("""{"id":7,"tags":["a","b"]}""")

// Segment ingest: one dictionary, one builder, many documents.
val builder = VariantBuilder(dictionary)
for (document in documents) {
builder.reset()
parser.parseInto(builder, document)
store(builder.build())
}

Instances are stateless and safe to reuse; the parse itself is single-threaded.

Constructors

Link copied to clipboard
constructor(maxDepth: Int = DEFAULT_MAX_JSON_DEPTH)

Functions

Link copied to clipboard
fun parse(json: ByteArray): Variant
fun parse(json: String): Variant

Parses json into a self-contained Variant with a dictionary of its own.

Link copied to clipboard
fun parseInto(builder: VariantBuilder, json: ByteArray)

Parses json into builder, which supplies the dictionary and the duplicate-field policy.

fun parseInto(builder: VariantBuilder, json: String)

See the ByteArray overload.