Converting circular structure to JSON
See original GitHub issueI’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:
- Created 6 years ago
- Comments:17
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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!
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);