DEV Community

Tsumuri
Tsumuri

Posted on • Edited on

Workaround of [object Object]

When JavaScript handles an object such as json andthe result is output,

[object Object]

maybe displayed.
This is because we are trying to output the data in object format as it is.
This can be solved by converting the number to a string.

//json_object => [object Object] Error Workaround
JSON.stringify(json_object);
Enter fullscreen mode Exit fullscreen mode

and solve it.
I look forward to helping you.

Top comments (2)

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.