JSON serialization behavior changed in P11

In mobile app, when we pass a structure as javascript Object parameter (wrapped in ToObject()), then in P11 JSON.stringify() fails with error:

VM2342:1 Uncaught TypeError: Converting circular structure to JSON

    --> starting at object with constructor 't'

    --- property 'propagationParent' closes the circle

If we do JSON.stringify($parameters.Record.data)) - it works;

Also toJS() exists in data only (in P10 - also in parameter itself)


Can someone advise, is this a known issue, and is there some workaround that can be done instead of changing all places in code where we have this?

Without reproducing the issue myself it is hard to find the most appropriate solution to your problem.

What I do remember is that many months ago we ran into a similar problem when upgrading to P11.

All I can see that was changed in the code was that on the object in question, we used the JSON.parse(object) method instead of using object.toJSON() method.

Otherwise, you might find something useful on this page: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/Cyclic_object_value

Code from link:

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

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


Hope this helps at least a bit