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.

TypeError: Converting Circular structure to JSON

See original GitHub issue

So I’m attempting to delete a row inside my psql database, a very simple structure with 4 rows + the auto ID:

CREATE TABLE public.tags
(
  id bigint NOT NULL DEFAULT nextval('tags_id_seq'::regclass),
  tag character varying(32) NOT NULL,
  description character varying(256) NOT NULL,
  server character(18) NOT NULL,
  added_by character(18) NOT NULL,
  CONSTRAINT tags_pkey PRIMARY KEY (id)
)

Attempting to reproduce the .del() example, I have the following code: knex('tags').where('tag', 'test').del();

I get the following error output to me: TypeError: Converting circular structure to JSON

I’m unsure what could cause this, and how to resolve it. Any ideas?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
tgriessercommented, Jun 21, 2016

So this is what I’m guessing might be a similar problem to #1522, the async behavior isn’t kicked off unless the query is executed w/ then or similar.

If you put .then() on the end of the .del() it will executed the promise:

knex('tags').where('tag', 'test').del().then(data => {
  console.log(data)
}).catch(e => {
  console.error(e)
});

The TypeError: Converting circular structure to JSON shows up when you trying to JSON.stringify something which has a reference to itsself, which is probably happening when JSON.stringify a query building chain that hasn’t been executed, rather than its return result from the promise or callback.

0reactions
elhigucommented, Jun 22, 2016

@eslachance I didn’t have that issue, because I didn’t ran the query, just checked what kind of SQL generates from it.

I still have no idea where in the code you are trying to convert object with circular dependencies to json string 😃 Great that you got your problem solved!

Functionality how queries are triggered is described in:

http://knexjs.org/#Builder http://knexjs.org/#Interfaces-Promises http://knexjs.org/#Interfaces-Callbacks http://knexjs.org/#Interfaces-Streams

pull requests to improve documentation are always welcome!

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 ...
It means that the object you pass in the request (I guess it is pagedoc ) has a circular reference, something like: var...
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. To solve...
Read more >
Converting Circular Structure to JSON - Career Karma
JSON does not support object references, so trying to stringify a JSON object that references itself will result in a typeerror. It is...
Read more >
How to fix TypeError: Converting circular structure to JSON in ...
To fix this error, you need to make sure that your objects don't contain circular references. One way to do this is to...
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