twilio-node: TypeError: Converting circular structure to JSON

Version: 3.8.1

Code Snippet

const twilio = new Twilio(creds.accountSid, creds.authToken);
const chatClient = twilio.chat.services(creds.chatServiceSid);

// ....
JSON.stringify(chatClient.channels(id).fetch())

Exception/Log

TypeError: Converting circular structure to JSON

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 7
  • Comments: 18 (7 by maintainers)

Most upvoted comments

I’ve created a ticket internally to evaluate the different options and implement one so we should hopefully get to this in the near future.

A toJSON method has been added to all instance objects in 3.13.0. Thank you all for your patience.

I’ve created this PR which should solve this issue, would appreciate any feedback you all have.

https://github.com/twilio/twilio-node/pull/325

For now I’ve written this utility that removes some of the keys (that I anyways didn’t really want) and that removes all the circular references.

import R from 'ramda';

const dangerous = ['_version', '_context', '_solution'];
const omit = R.omit(dangerous);

export default data => {
  if (R.is(Array, data)) {
    return { data: R.map(omit, data) };
  } else {
    return omit(data);
  }
};

I think there should be an options object that we could pass while instantiating twilio which could remove these references for us.

import Twilio from 'twilio';
const twilio = new Twilio(,,, { lean; true })