Closed FranciscoCastle closed 2 months ago
I'm happy to fix it
I'm happy to fix it
Shouldn't it just display issue?
Since REPL
or console.log
do not like browser provide a way to expend each property, the display of [Object]
still means it is a proper object
.
https://nodejs.org/api/util.html#utilinspectobject-showhidden-depth-colors
The maximum depth
of console.log
show is 2
.
import pug from 'pug'
const html = pug.render('p= data', {
data: {
string: 'example text',
object: { string: 'text 2', object: { string: 3 } } // not [Object]
}
})
console.log(html) // <p>[object Object]</p>
pug
is actually printing the object
using .toString
and that is expected result.
Sounds reasonable, the default depthof
console.logis 2, that's why
{ string: 3 }` doesn't been shown, but I haven't found any doc to describe it.
but I haven't found any doc to describe it.
console.log
said it using util.format
.
util.format
said it using util.inspect
for object
.
util.inspect
is telling you depth
is 2
by default.
It has nothing to do with JSON.parse()
, as @climba03003 mentioned it's the documented behavior of console.log()
. You should first convert the data to a string with e.g. JSON.stringify()
, util.format()
, or a third party library.
In your code, you're correctly stringifying an object and then parsing it back into an object. However, when you pass _data to your Pug template, you're assigning the entire object to a variable called data. This is why you're seeing [object Object] in your view because data is an object, and Pug is displaying it as a string representation.
(This issue seems resolved)
Version
21.7.1
Platform
Microsoft Windows NT 10.0.22631.0 x64
Subsystem
No response
What steps will reproduce the bug?
How often does it reproduce? Is there a required condition?
All the time I run my app in nodejs
in my browser console it works correctly:
What is the expected behavior? Why is that the expected behavior?
What do you see instead?
result in console:![image](https://github.com/nodejs/node/assets/30781874/984a5604-e7a7-4961-9ee3-27f28f6ce3a5)
Additional information
I would like to send an object to my view in Pug but when reading it in Pug I only get this in the view:
index.js:
index.pug: