fix(console): implement %j format specifier for JSON output

Merged
RO
1y ago
+85-1

Summary

  • Implements the %j format specifier for console.log and related console methods
  • %j outputs the JSON stringified representation of the value
  • Previously, %j was not recognized and was left as literal text in the output

Test plan

  • Run bun bd test test/regression/issue/24234.test.ts - all 5 tests pass
  • Verify tests fail with system Bun (USE_SYSTEM_BUN=1) to confirm fix validity
  • Manual verification: console.log('%j', {foo: 'bar'}) outputs {"foo":"bar"}

Example

Before (bug):

$ bun -e "console.log('%j %s', {foo: 'bar'}, 'hello')"
%j [object Object] hello

After (fixed):

$ bun -e "console.log('%j %s', {foo: 'bar'}, 'hello')"
{"foo":"bar"} hello

Closes #24234

šŸ¤– Generated with Claude Code