JavaScript error: Circular structure unable to convert to JSON format was caught

Here is a JSON object I have:

[#1={id:"2012-05-04", title:"Scheduled", start:(new Date(1336096800000)), source:{events:[#1#], className:[]}, _id:"2012-05-04", _start:(new Date(1336089600000)), end:null, _end:null, allDay:true, className:[]}]

I attempted to stringify it as follows:

var test = JSON.stringify(resourceVacation, censor(resourceVacation));

function censor(censor) {
    return (function() {
        var i = 0;
        return function(key, value) {
            if (i !== 0 && typeof(censor) === 'object' && typeof(value) == 'object' && censor == value)
                return '[Circular]';

            ++i; // so we know we aren't using the original object anymore

            return value;
        }
    })(censor);
}

I used censor based on this information :Chrome sendrequest error: TypeError: Converting circular structure to JSONn

However, I encountered the following browser exception:

Uncaught TypeError: Converting circular structure to JSON

Here is the JavaScript object:

The previous JSON object was obtained using toSource() at Mozilla browser. Any suggestions on how to resolve this issue !!

============================UPDATE========================

Let me provide you with the scenario from the beginning: 1 -Initially: I have a form and at the end I construct a JavaScript object which looks like:

#1=[{id:"2012-05-03", title:"Scheduled", start:(new Date(1336010400000)), source:{events:#1#, className:[]}, _id:"2012-05-03", _start:(new Date(1336003200000)), end:null, _end:null, allDay:true, className:[]}]

This object can be stringified without any issues ... KEEP IN MIND THAT IT IS similar to the one causing an exception later.

2- Later on, I remove objects from this array using :

function deleteVacation(day) {
    for (var index = 0; index < resourceVacation.length; index++) {
        if (resourceVacation[index].id == day)

            resourceVacation.splice(index,1);
    }

3-When I attempt to stringify that array after deleting a single object, I encounter the mentioned exception. So .. any thoughts on why it worked the first time but failed the second time !!

Answer №1

It is not possible to encode date objects in JSON format.

According to json.org: "A value can be a string enclosed in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested."

Answer №2

The issue lies in the origin - an object that forms a circular reference.

To resolve this problem, you must duplicate the object while excluding the original source.

This is how I successfully tackled the FullCalendar problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

JSON array serving as a matrix for options available in DropDownLists

In my XSLT stylesheet, I have routines that process XML files to display products on a web page (ASP.NET). The XSLT outputs HTML for presenting the product along with its variations like size, color, package quantity, and style. The variations are treated ...

What is the method for displaying posts using JavaScript?

I'm experiencing an issue and could use some assistance. For instance, if I have HTML code like this: <div class="posts"> posts 1 </div> <div class="posts"> posts 2 </div> <div class="posts"> posts 3 </div&g ...

Is it possible to activate every function within a prototype?

When presented with a class structure as demonstrated below, I am able to iterate through all its PropertyNames using console.log. class Security { constructor(param: ParamType) { this.method1(param); ... this.methodN(param); } method1(p ...

Guide on deactivating the div in angular using ngClass based on a boolean value

displayData = [ { status: 'CLOSED', ack: false }, { status: 'ESCALATED', ack: false }, { status: 'ACK', ack: false }, { status: 'ACK', ack: true }, { status: 'NEW', ack ...

Troubleshooting Vue.js 2: Difficulty with Vue locating files stored in the /assets directory (v-for loop)

My Vue-cli 3 project with Webpack has the following folder structure: /public /src /assets p1.jpg p2.jpg App.vue main.js I have read that in order for Webpack to recognize the /assets directory, require() should be used in JavaScript files ...

Is there a way to disable a JavaScript hover effect when the mouse moves away?

I came across this JavaScript code that swaps the background of a parent div when clicking on a link in a child div. However, I noticed that the hover state remains even after moving the mouse out of the link. Can someone help me modify the code so that ...

Issue with Three JS canvas not adjusting to fit mobile device window width

I'm currently exploring the world of 3D animations using Three JS and I've set out to create a project involving multiple spinning cubes. However, I've encountered an issue where the canvas doesn't resize correctly when zooming in or ou ...

Creating and implementing a Lift/Scala Json webservice from a mapper persistant class

Greetings, fellow community members! I am relatively new to posting questions here, so please be patient with me. Despite my best efforts scouring the depths of the internet, I seem to be struggling with a seemingly simple task - perhaps I'm just a b ...

The preventDefault method is failing to prevent the default action when placed within a

I am having trouble using preventdefault to stop an action. I'm sorry if the solution is obvious, but I can't seem to locate the mistake. Why isn't it preventing the link from being followed? Here is a link to my jsfiddle: http://jsfiddle.ne ...

The execution of the 'yarn start-https' command encountered an error and exited with code 1

Struggling to set up the environment for a downloaded project. After running yarn install, yarn build, and yarn start-https, I encountered this error message: Error: error:0909006C:PEM routines:get_name:no start line at node:internal/tls/secure-context ...

Jackson converting XML attribute into simplified JSON format

I'm facing a challenge with converting this XML data into JSON using Jackson 2.8. Here is the sample XML structure: <testCode code="ABC" lang="java" /> Below are the corresponding POJO classes: @XmlAccessorType(XmlAccessType.FIELD) @XmlType(n ...

How to Use JQuery Load to Load Google Maps?

Is it possible to ensure that the initialize() function is executed in the correct sequence of events so that a Google Map v3 API map can be loaded via a JQuery .load() method? The current code structure I've implemented is as follows: $('#mapl ...

Save an array of messages by making separate API calls for each one

I have a function that makes an API call to retrieve a list of message IDs. Here is the code: function getMessageList(auth) { api.users.messages.list({ auth: auth, userId: 'me', }, function(err, response) { if (er ...

Ways to switch text on and off smoothly using transitions

I have created a webpage where text starts off hidden but has a visible heading. When you click on the heading, the text is revealed below. I am putting the final touches and aiming to make the text slide in smoothly. I am using Javascript for toggling ins ...

Tips for keeping the most recently opened accordion in a group by using the is-open attribute to call a function

I have a dynamically populated accordion that updates every 15 seconds. I need to keep track of the last opened accordion group as the dataList can be very large and parsing it for each update is not feasible. Below is the code snippet from my HTML file: ...

Utilizing Literal and Instance Formats in JavaScript

There are two main methods for creating JavaScript objects. The confusion arises in understanding when to use each notation. Below are examples of both literal and instance variables, each holding different values and producing different results when opera ...

Is there a way to combine two JSON objects within an Android spinner?

After fetching data from my database, is it feasible to combine both objects into a single object? Below is the Android code snippet for retrieving data for a spinner: spinner1 = (Spinner) findViewById(R.id.sp1); final List<String> list1 = ...

Ways to retain previously entered text in the autocomplete feature

My issue involves using a JavaScript autocomplete widget that displays suggestions as I type, but erases my input when I try to browse the list using the down key. YOUR TEXT HERE serves as a placeholder. While not exactly the same problem, you can view ...

What is the best way to convert a dynamic JSON into a string?

After verifying the following Json as valid on www.jsonlint.com, I found that it is too large to display in its entirety. Below is a snippet: { "data": [{ "name": "Michael Jackson", "pic_large": "https://scontent.x.fbcdn.net/v/t1.0-1/p ...

Error: WebView element type is not valid. A valid string was expected

Here is my basic React code : import React from "react"; import { Text, StyleSheet,View } from "react-native"; import { WebView } from 'react-native'; const App = () => { return( <WebView source={{ ...