Skip to documentation
SLOP

tiny.preserves.toJsonString

Reference tiny.preserves toJsonString

Defined in json.

Returns value as minified JSON text, allocated with alloc, for code that logs or sends a value to a JSON consumer.

Called byCallsprivate sourcelib.preserves.src.jsoncheckJsonEncodingAllocationFailurestest sourcelib.preserves.src.jsontest: $capture / $bind / $rest round-...test sourcelib.preserves.src.jsontest: toJsonString: NaN and Inf round...test sourcelib.preserves.src.jsontest: toJsonString: Observe record us...test sourcelib.preserves.src.jsontest: toJsonString: discard envel...+7 moreprivate sourcelib.preserves.src.jsonwriteJsonjsontoJsonString
Static calls · unresolved targets: 1 · external targets: 2.

Source

Source: lib/preserves/src/json.zig:98

zig
/// Returns `value` as minified JSON text, allocated with `alloc`, for code that logs or sends a/// value to a JSON consumer. The caller owns the returned bytes and frees them with `alloc`./// Booleans, strings and sequences become their JSON counterparts, and sets become arrays. The/// symbol `null` becomes JSON null, and every other symbol becomes a JSON string. A byte string/// becomes a string of lowercase hexadecimal digits. If a double is non-finite, it becomes null. An/// integer too wide for 128 bits becomes a 64-bit number that differs from it. A dictionary becomes/// an object: string and symbol keys become member names, and other keys are written in the text/// syntax. A record whose label is a protocol name becomes `{"type": …}` with named fields, and/// each field past the named ones takes the name `f` plus its index. If a record has a symbol label/// and either zero fields or one dictionary field with string keys, the record becomes/// `{"type": label}` plus the dictionary's entries. Any other record becomes/// `{"__record__": label, "fields": […]}`. The discard pattern becomes `{"__discard__": true}`, and/// captures, binds and rest patterns become `$capture`, `$bind` and `$rest` objects. An embedded/// value becomes `{"__embedded__": "…"}` holding its pointer as a decimal string. The call frees/// what it wrote so far on any error.pub fn toJsonString(alloc: Allocator, value: Value) EncodeError![]const u8 {    var out: std.Io.Writer.Allocating = .init(alloc);    errdefer out.deinit();    var json = JsonWriter.init(&out.writer, .minified);    writeJson(alloc, &json, value) catch |err| switch (err) {        error.WriteFailed => return error.OutOfMemory,        else => return @errorCast(err),    };    return try out.toOwnedSlice();}

Source: lib/preserves/src/root.zig:304

zig
pub const toJsonString = json.toJsonString;

Complete caller list

12 direct callers.

Audit

Definitions1
Public names2
Members0
Version26.7.0
Revisiondaab053ee433