Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

395
Views
TypeError: Converting circular structure to JSON - AWS Lambda

I know, this question has been asked a bunch of time. But I really don't know what's wrong with my code here. How can I fix this type error?

Where do I have a circular structure?

I'm running this code in a AWS Lambda function:

const addRanksToDB = async (tableName, stats) => {
  return Promise.all(Object.keys(stats).map(async (slug) => {
    const projectSlug = slug;
    const rankData = stats[slug];

    const messageBody = {
      rowId: projectSlug,
      table: tableName,
      identifier: 'project_slug',
      action: 'insert',
      payload: {
        project_slug: projectSlug,
        ...rankData,
        last_updated: knexClient.fn.now(),
      },
    };

    return sqs.sendMessage({
      MessageBody: JSON.stringify(messageBody),
      QueueUrl: 'https://sqs.eu-central-1.amazonaws.com/599632852002/handleDataInDBQueue',
    }).promise();
  }));
};

The rankData object looks like this:

{
  one_day_volume: 191,
  seven_day_volume: 162,
  thirty_day_volume: 179,
  total_volume: 156,
  num_owners: 4,
  average_price: 129,
  market_cap: 66,
  floor_price: 146
}

And this is the error I'm getting:

{
    "errorType": "TypeError",
    "errorMessage": "Converting circular structure to JSON\n    --> starting at object with constructor 'Timeout'\n    |     property '_idlePrev' -> object with constructor 'TimersList'\n    --- property '_idleNext' closes the circle",
    "trace": [
        "TypeError: Converting circular structure to JSON",
        "    --> starting at object with constructor 'Timeout'",
        "    |     property '_idlePrev' -> object with constructor 'TimersList'",
        "    --- property '_idleNext' closes the circle",
        "    at JSON.stringify (<anonymous>)",
        "    at /var/task/src/handlers/stats/webpack:/handlers/stats/rankProjectsByStatsCronjob.js:84:27",
        "    at Array.map (<anonymous>)",
        "    at v (/var/task/src/handlers/stats/webpack:/handlers/stats/rankProjectsByStatsCronjob.js:67:43)",
        "    at Runtime.R [as handler] (/var/task/src/handlers/stats/webpack:/handlers/stats/rankProjectsByStatsCronjob.js:188:23)",
        "    at processTicksAndRejections (internal/process/task_queues.js:95:5)"
    ]
}

The error is pointing to the line with MessageBody: JSON.stringify(messageBody),. How can I structure my sqs message so that I dont get this error?

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!