KhoPhi
KhoPhi

Reputation: 9527

Converting circular structure to JSON Firebase

enter image description here

The above is the returned object from firebase and I do this:

JSON.stringify(data) // where data is the returned object

Then I get the error: TypeError: Converting circular structure to JSON

How to properly handle an object response like that from firebase?

This answer paints a picture of what is happening, however, in the case of firebase, how to go about it?

Upvotes: 4

Views: 5024

Answers (2)

Mark A Durham
Mark A Durham

Reputation: 21

The proper way to handle the error "TypeError: Converting circular struct to JSON" when getting data from Firebase is to enumerate the key/value pairs explicitly and examine them:

Object.keys(data).forEach((key) => {
   let value = data[key];
   console.log(key + " : " + value);
});

The data you have is almost certainly not the data you think you have.

Upvotes: 0

cderrick
cderrick

Reputation: 76

You have to call the val() method...

JSON.stringify(data.val())

Upvotes: 4

Related Questions