JSON.stringify provides a way for objects to customize their serialization process by defining a function named toJSON.
Here is an excerpt from the MDN documentation:
toJSON() behavior
If an object being converted to a string has a method called toJSON, that method can be used to customize the JSON serialization process. Instead of directly serializing the object, the value returned by the toJSON() method will be serialized.
Is there a method to override this behavior and force JSON.stringify to ignore any existing toJSON methods and use its default serialization process?
The reason for this query is that there are some buggy toJSON methods present in my environment due to a JavaScript library. These bugs have caused certain inaccuracies in the serialized data format, which are now accepted by the server-side code. While I cannot remove these faulty methods, I would like JSON.stringify to disregard them moving forward.