TypeError Converting circular structure to JSON in nodejs

0 votes

Code :

 var formData = ({first_name:firstname,last_name:lastname,user_name:username, email:email,password:password});


  request.post({url:'http://localhost:8081/register', JSON: formData}, function(err, connection, body) {


exports.Register = function(req, res) {

    res.header("Access-Control-Allow-Origin", "*");

    console.log("Request data " +JSON.stringify(req));

This is a request package for node.js. But I am getting this error in return:

TypeError: Converting circular structure to JSON

Can someone help me with this?

May 13, 2022 in Java-Script by Kichu
• 19,040 points
4,065 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

The issue is that Javascript won't accept circular objects. If it has a reference of JSON.stringify() then it will throw an error. What you need to do is to log the object to the console,  you can use the console's native stringifying and avoid using JSON:

console.log("Request data:");
console.log(req);

I hope this helps you.

answered May 15, 2022 by narikkadan
• 63,600 points

edited Mar 5

Related Questions In Java-Script

0 votes
1 answer
0 votes
1 answer

How to print a circular structure in a JSON-like format?

Hello, You can use util.inspect(object) in node.js. It automatically ...READ MORE

answered Apr 24, 2020 in Java-Script by Niroj
• 82,840 points
3,132 views
0 votes
1 answer

How do I turn a string to a json in Node.js?

Hello Kartik, Use the JSON function  JSON.parse(theString) ...READ MORE

answered Apr 24, 2020 in Java-Script by Niroj
• 82,840 points
1,112 views
0 votes
1 answer

Uncaught TypeError: Cannot use 'in' operator to search for '324'

Hello @kartik, You have a JSON string, not ...READ MORE

answered Jun 18, 2020 in Java-Script by Niroj
• 82,840 points
8,760 views
0 votes
1 answer

Error:jQuery.parseJSON throws “Invalid JSON” error due to escaped single quote in JSON

Hello @kartik, Striking a similar issue using CakePHP ...READ MORE

answered Jun 19, 2020 in Java-Script by Niroj
• 82,840 points
5,239 views
0 votes
1 answer

How to “pretty” format JSON output in Ruby on Rails?

Hello @kartik, Use the pretty_generate() function, built into later versions ...READ MORE

answered Jul 24, 2020 in Java-Script by Niroj
• 82,840 points
12,424 views
0 votes
1 answer

Start script missing error when running npm start

It seems that there is an undefined ...READ MORE

answered Feb 10, 2022 in Java by Soham
• 9,710 points
4,597 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
2,062 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,596 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP