DEV Community

Workaround of [object Object]

Tsumuri on March 26, 2022

When JavaScript handles an object such as json andthe result is output, [object Object] maybe displayed. This is because we are trying to outpu...
Collapse
 
dontay profile image
Don Tay

To add on, if you would like to pretty print the json object, you can this:

JSON.stringify(json_object, null, 2);
Enter fullscreen mode Exit fullscreen mode

Instead of printing an object like this (as in the original example):

{a: {b: 1}}
Enter fullscreen mode Exit fullscreen mode

it will print it like this:

{
  a: {
    b: 1
  }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
tsumuri1017 profile image
Tsumuri

Very descriptive description. Thank you.