Vullnetarët tanë s’e kanë përkthyer ende në Shqip këtë artikull. Merrni pjesë dhe ndihmoni të mbarohet kjo punë!
Mund ta lexoni artikullin edhe në English (US).


TypeError: cyclic object value (Firefox)
TypeError: Converting circular structure to JSON (Chrome and Opera)
TypeError: Circular reference in value argument not supported (Edge)

Error type


What went wrong?

The JSON format per se doesn't support object references (although an IETF draft exists), hence JSON.stringify() doesn't try to solve them and fail accordingly.


In a circular structure like the following

var circularReference = {otherData: 123};
circularReference.myself = circularReference;

JSON.stringify() will fail

// TypeError: cyclic object value

To serialize circular references you can use a library that supports them (e.g. cycle.js) or implement a solution by yourself, which will require finding and replacing (or removing) the cyclic references by serializable values.

The snippet below illustrates how to find and filter (thus causing data loss) a cyclic reference by using the replacer parameter of JSON.stringify():

const getCircularReplacer = () => {
  const seen = new WeakSet();
  return (key, value) => {
    if (typeof value === "object" && value !== null) {
      if (seen.has(value)) {
    return value;

JSON.stringify(circularReference, getCircularReplacer());
// {"otherData":123}

See also

  • JSON.stringify
  • cycle.js – Introduces two functions, JSON.decycle and JSON.retrocycle, which makes it possible to encode and decode cyclical structures and dags into an extended and retrocompatible JSON format.

Etiketa dhe Kontribues Dokumentesh

Kontributorë te kjo faqe: PatrickKettner, grantcarthew, fsarachu, jonasraoni, fscholz
Përditësuar së fundi nga: PatrickKettner,