question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Converting circular structure to JSON

See original GitHub issue

I’m making an app with NuxtJs and after update Axios from 0.15.3 to 0.16.1, I got bellow error.

TypeError: Converting circular structure to JSON
    at Object.stringify (native)
    at serialize (/home/masoud/Sources/cynthia-mobile/node_modules/serialize-javascript/index.js:72:20)


  • axios version: 0.16.1
  • Environment: e.g.: node v6.10.0, chrome 57, ubuntu 16.04

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:17

github_iconTop GitHub Comments

52reactions
kmedacommented, Jul 20, 2017

const axios = require(‘axios’); const CircularJSON = require(‘circular-json’);

axios.get(url, config).then((response)=>{ let json = CircularJSON.stringify(response); res.send(json); }).catch((error)=>{ console.log(error); });

This worked for me!

30reactions
jordvaugcommented, Mar 14, 2019

This error will also occur if you are try to include the response from axios in your response as shown below. (res.json(response)😉 apiRouter.post( "/mtp/:email", jwt({ secret: process.env.SECRET }), (req, res) => { var host = "https://www.mountainproject.com"; var path = "/data/get-user?email=" + req.params.email + "&key=" + process.env.MTPKEY; var url = host + path; axios .get(url) .then(response => { res.json(response); }) .catch(err => { res.status(500).send(err); }); } );

Simple fix is to make sure you are referencing response.data res.json(response.data);

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is TypeError: Converting circular structure to JSON?
TypeError: Converting circular structure to JSON occurs when you try to reference your variable name within the JSON object.
Read more >
TypeError: Converting circular structure to JSON - Stack ...
TypeError: Converting circular structure to JSON. It seems that I can get the object logged to the console by using just plain: console.log(object)....
Read more >
TypeError: Converting circular structure to JSON in JS
The "Converting circular structure to JSON" error occurs when we pass an object that contains circular references to the JSON.stringify() method.
Read more >
Converting Circular Structure to JSON - Career Karma
On Career Karma, learn about the restrictions of JSON in the debugging tutorial for converting circular structure to json.
Read more >
How to print a circular structure in a JSON like format using ...
The circular structure is when you try to reference an object which directly or indirectly references itself. ... Here you can easily resolve...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found