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.
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.
lib.preserves.src.json.checkJsonEncodingAllocationFailures[function] — private source atlib/preserves/src/json.zig:756in nearest public ownertiny.preserves.jsonlib.preserves.src.json.test_$capture_/_$bind_/_$rest_round-trip_through_JSON[function] — test source atlib/preserves/src/json.zig:832in nearest public ownertiny.preserves.jsonlib.preserves.src.json.test_toJsonString:_NaN_and_Inf_round_to_null[function] — test source atlib/preserves/src/json.zig:520in nearest public ownertiny.preserves.jsonlib.preserves.src.json.test_toJsonString:_Observe_record_uses_protocol_mapping[function] — test source atlib/preserves/src/json.zig:577in nearest public ownertiny.preserves.jsonlib.preserves.src.json.test_toJsonString:___discard___envelope[function] — test source atlib/preserves/src/json.zig:570in nearest public ownertiny.preserves.jsonlib.preserves.src.json.test_toJsonString:_byte_string_as_hex-packed_string[function] — test source atlib/preserves/src/json.zig:531in nearest public ownertiny.preserves.jsonlib.preserves.src.json.test_toJsonString:_embedded_values_use_decimal_pointer_strings[function] — test source atlib/preserves/src/json.zig:598in nearest public ownertiny.preserves.jsonlib.preserves.src.json.test_toJsonString:_nested_dictionaries_preserve_wide_values_and_escaping[function] — test source atlib/preserves/src/json.zig:539in nearest public ownertiny.preserves.jsonlib.preserves.src.json.test_toJsonString:_primitives[function] — test source atlib/preserves/src/json.zig:500in nearest public ownertiny.preserves.jsonlib.preserves.src.json.test_toJsonString:_unknown_symbol-label_record_uses___record___envelope[function] — test source atlib/preserves/src/json.zig:618in nearest public ownertiny.preserves.jsonlib.preserves.src.json.test_toJsonString_+_fromJsonString:_sequence_round-trip[function] — test source atlib/preserves/src/json.zig:714in nearest public ownertiny.preserves.jsonlib.preserves.src.json.test_toJsonString_rejects_duplicate_set_elements_and_dictionary_keys[function] — test source atlib/preserves/src/json.zig:738in nearest public ownertiny.preserves.json
Audit
| Definitions | 1 |
|---|---|
| Public names | 2 |
| Members | 0 |
| Version | 26.7.0 |
| Revision | daab053ee433 |