-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
console.json #222
Comments
There is already a similar |
@terinjokes Yeah Example:
Outputs: Of course, you can pass the
However, much of the object is still obfuscated. Okay, so
Boo, still [Object]. Well thats because I didn't specify depth far enough. Sigh. Okay lets guess some more about the right depth:
Bollocks! I can see the lower keys now, but still not the values. Of course, I can try again with another depth that will show what Proposed Improvements in
|
When I run your top example in Firefox, I get the following, which I believe is the requested behavior? {
"a": {
"b": {
"c": {
"d": {
"e": {
"f": {
"g": {
"foo": "bar",
"array": [
1,
2,
3,
4,
5
]
}
}
}
}
}
}
}
} I would expect |
How console methods render is implementation defined. This specification defines |
Browser consoles are interactive, where's node's console emits non-interactive text to stdout.. It does seem like the proposed solution is to work around node's default depth (and lack of interactivity)... I've left a reply on nodejs/node#46689 |
@paulirish agreed, browser consoles are always going to have vendor specific implementations on this stuff. I originally opened this discussion as a thread in node.js since browsers weren't really what I had in mind from the start. I was told by that team to come here, so thats why I'm here lol. Thanks for commenting on the original thread. |
Unfortunately I don't think there is too much here that's actionable since as Terin mentioned, this is very much implementation-specific territory. That is, if we were to spec |
@domfarolino for me, I still think that it should be considered more significantly. In 2023, JSON is a first class citizen with a nearly unmatched ubiquity in the web-development world. While there are of course vendor specific details and implementation-specific liberties in the console spec, To tackle the browser implementation-specific objection head-on, I would argue that in heavy debug cycles, being able to stringify an object directly to JSON via (console.json(<serializable)) in the developer console would be immensely useful far and above what console.dir achieves because of the interoperability and usability of getting data in to JSON quickly and easily for use in other dev tools. Further, I would argue that console.json has no implementation-specific considerations or liberties since JSON is well defined by RFC-8259, and, unlike console.dir, the output format is fixed: its a string, as defined by it's RFC. This simplifies and removes ambiguity about browser-specific implementations since JSON is a string, and since auto-magic object tree structuring in browser UIs generally exists already, there would be no reason for browsers to implement The suite of Thanks again for your consideration on this topic. |
I think this would be better resolved by working with your user-agent to provide the options you want to for |
@terinjokes On the browser side, I hear ya. The challenge is, the node.js team follows your standard strictly (which is why they sent me here). So this is not an issue I feel necessarily needs to be addressed for browser-based development where use-agent is in play, but about the downstream subscribers to this standard like node.js. Maybe if you know anyone on the node.js team, you can let them know these types of deviations are anticipated in contexts where we are dealing with a specific applications implementation of the standard? |
The vast majority of data transmission in today's javascript ecosystem happens via JSON serialized objects. For node.js developers, serializing objects to inspect them is a mainstay of iterative debugging.
However, as many, many objects are nested, being able to easily inspect the entire object in the console is cumbersome.
console.log(JSON.stringify(<serializable>, null, 2))
has been coded more times in my career than I ever want to count lol.Given the fact that JSON is ubiquitous in 2023, that JS is object-based by default (meaning the majority of object structures are JSON-serializable), and that it would just be insanely useful, helpful to developers, I want to propose that the whatwg console standard be extended to include
console.json
In an ideal world, calling console.json() would perform a similar duty as
console.log(JSON.stringify(<serializable>, null, 2))
but with a lot less syntax.An argument to pretty print or not would seem reasonable. If for verbosity sake an argument to limit the depth of iteration was desired, that would be a reasonable argument/ask in my mind.
Otherwise this seems like a straight-forward and immensely helpful standard extension, especially for node.js developers.
The text was updated successfully, but these errors were encountered: