4

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?

Community
  • 1
  • 1
KhoPhi
  • 9,660
  • 17
  • 77
  • 128

2 Answers2

4

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

JSON.stringify(data.val())
cderrick
  • 76
  • 7
  • You know what, I'm really far away from my Firebase code at the moment, but I think this will do the trick. Will let you know how it goes! Thanks – KhoPhi Dec 20 '16 at 23:48
0

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.