console: add console.json() method - #65251
Closed
magicmark wants to merge 4 commits into
Closed
Conversation
Adds `console.json(...values)` which serializes each argument using `JSON.stringify` with 2-space indentation, printing to stdout. Each value is printed on a separate line. Motivation: inspecting objects via `console.log` applies `util.inspect` formatting, which adds annotations like `[Object: null prototype]` that are noise when you just want the plain data. `JSON.stringify` already handles null-prototype objects cleanly, so this is a thin wrapper that makes the common pattern `console.log(JSON.stringify(x, null, 2))` first-class. Non-serializable top-level values (undefined, functions, symbols) are silently skipped, matching the behavior of JSON.stringify returning undefined for them. Circular references throw a TypeError. Refs: whatwg/console#222 Co-Authored-By: Claude <noreply@anthropic.com>
Pass all arguments directly to JSON.stringify, matching the semantics of console.json = (...args) => console.log(JSON.stringify(...args)). No default indentation — caller controls formatting via JSON.stringify's own replacer/space arguments. Co-Authored-By: Claude <noreply@anthropic.com>
Serialize each argument independently rather than splatting all args into JSON.stringify — so console.json(a, b) prints two lines, not treating b as a replacer. Co-Authored-By: Claude <noreply@anthropic.com>
Match JSON.stringify's own signature rather than using rest args. Co-Authored-By: Claude <noreply@anthropic.com>
avivkeller
requested changes
Aug 12, 2026
avivkeller
left a comment
Member
There was a problem hiding this comment.
Node.js cannot land a console method not in the Console specification.
Member
|
I'm closing this PR as it does not abide by our AI Guidelines. Specifically, the "Own every line you submit" clause has been violated, as the commits have not been signed off by the author, and your agent wrote that it's contents were not human reviewed in the description. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds
console.json(value[, replacer[, space]])as a thin wrapper overJSON.stringify. Arguments pass through directly, so the caller controls formatting — no default indentation imposed.Equivalent to:
The motivation is inspecting objects without
util.inspect's annotations. The canonical case is null-prototype objects, which print as[Object: null prototype] { foo: 'bar' }viaconsole.logbut cleanly as{"foo":"bar"}viaJSON.stringify.Refs: whatwg/console#222
Draft PR: This PR was sent by Claude and may not have yet been reviewed by mark.