aboutsummaryrefslogtreecommitdiff
path: root/lib/std/json/stringify.zig
AgeCommit message (Collapse)Author
2025-07-19std.json: update to new I/O APIAndrew Kelley
also do a little bit of namespace cleanup
2025-07-09std: fmt.format to io.Writer.printAndrew Kelley
allows reverting format -> deprecatedFormat, plus I think this is a nicer place for the function.
2025-07-07std.io.Writer.printValue: rework logicAndrew Kelley
Alignment and fill options only apply to numbers. Rework the implementation to mainly branch on the format string rather than the type information. This is more straightforward to maintain and more straightforward for comptime evaluation. Enums support being printed as decimal, hexadecimal, octal, and binary. `formatInteger` is another possible format method that is unconditionally called when the value type is struct and one of the integer-printing format specifiers are used.
2025-07-07std.fmt: breaking API changesAndrew Kelley
added adapter to AnyWriter and GenericWriter to help bridge the gap between old and new API make std.testing.expectFmt work at compile-time std.fmt no longer has a dependency on std.unicode. Formatted printing was never properly unicode-aware. Now it no longer pretends to be. Breakage/deprecations: * std.fs.File.reader -> std.fs.File.deprecatedReader * std.fs.File.writer -> std.fs.File.deprecatedWriter * std.io.GenericReader -> std.io.Reader * std.io.GenericWriter -> std.io.Writer * std.io.AnyReader -> std.io.Reader * std.io.AnyWriter -> std.io.Writer * std.fmt.format -> std.fmt.deprecatedFormat * std.fmt.fmtSliceEscapeLower -> std.ascii.hexEscape * std.fmt.fmtSliceEscapeUpper -> std.ascii.hexEscape * std.fmt.fmtSliceHexLower -> {x} * std.fmt.fmtSliceHexUpper -> {X} * std.fmt.fmtIntSizeDec -> {B} * std.fmt.fmtIntSizeBin -> {Bi} * std.fmt.fmtDuration -> {D} * std.fmt.fmtDurationSigned -> {D} * {} -> {f} when there is a format method * format method signature - anytype -> *std.io.Writer - inferred error set -> error{WriteFailed} - options -> (deleted) * std.fmt.Formatted - now takes context type explicitly - no fmt string
2025-07-07std.io: deprecated Reader/Writer; introduce new APIAndrew Kelley
2025-01-16all: update to `std.builtin.Type.{Pointer,Array,StructField}` field renamesmlugg
2025-01-16all: update to `std.builtin.Type.Pointer.Size` field renamesmlugg
This was done by regex substitution with `sed`. I then manually went over the entire diff and fixed any incorrect changes. This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since my regex happened to also trigger here. I opted to leave these changes in, since they *are* a correct migration, even if they're not the one I was trying to do!
2024-09-07Support stringifying non-exhaustive enum to json (#21228)pfg
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
2024-08-22std.json.WriteStream supports streaming long values directly to the ↵Josh Wolfe
underlying stream (#21155)
2024-05-03Delete compile errors for deprecated declsRyan Liptak
2024-04-06json.WriteStream.objectFieldRaw() (#19553)Josh Wolfe
2024-02-20json: make std.json.stringifyAlloc return a mutable slice (#19013)Techatrix
2023-12-28refact: rectifified a typo in docs of stringify.zigMarcius
2023-11-22std: remove meta.traitAndrew Kelley
In general, I don't like the idea of std.meta.trait, and so I am providing some guidance by deleting the entire namespace from the standard library and compiler codebase. My main criticism is that it's overcomplicated machinery that bloats compile times and is ultimately unnecessary given the existence of Zig's strong type system and reference traces. Users who want this can create a third party package that provides this functionality. closes #18051
2023-08-08std.json: stringify enum literals (#16742)Philipp Lühmann
2023-08-06std.json: josh review fixesJonathan Marler
* renamed enum_big_numbers_quoted option to enum_nonportable_numbers_as_strings * updated stringify doc to mention the option I also reversed the logic to determine whether an integer is nonportable, it seemed easier to reason about. I also took a stab at applying the new option to floats, but, I got stuck at trying to print large floats, not sure if Zig supports that yet.
2023-08-06json.stringify: properly implement RFC8259 recommendationJacob Young
The previous magic numbers used `1 << 52`, which did not account for the implicit leading one in the floating point format. The RFC is correct when it uses an exponent of 53. Technically these exclusive endpoints are also representable, but everyone including the RFC seems to use them exclusively. Also, delete special case optimizations related to the type which have already been implemented in the zig compiler to produce comptime values for tautological runtime comparisons.
2023-08-05std.json: fix roundtrip stringify for large integersJonathan Marler
std.json follows interoperability recommendations from RFC8259 to limit JSON number values to those that fit inside an f64. However, since Zig supports arbitrarily large JSON numbers, this breaks roundtrip data congruence. To appease both use cases, I've added an option `emit_big_numbers_quoted` to StringifyOptions. It's disabled by default which preserves roundtrip but can be enabled to favor interoperability.
2023-07-27std.json: WriteStream.print instead of writePreformattedJosh Wolfe
2023-07-22std.json.WriteStream: eliminate dead memory in optimized modes (#16485)Josh Wolfe
2023-07-21std.json: Unify stringify and writeStream (#16405)Josh Wolfe
2023-07-10explicitly specify error set of `std.json.stringify`Techatrix
2023-07-03json: give enums a default stringify implementationEvin Yulo
2023-07-03add docstring to std.json.stringify (#16241)yujiri8
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-05-13std: Rewrite low-level json api to support streaming (#15602)Josh Wolfe