Reports JSON.parse(JSON.stringify()) patterns that can use structuredClone.
✅ This rule is included in the ts logical presets.
The JSON.parse(JSON.stringify()) pattern has long been used for deep cloning objects in JavaScript.
However, the modern structuredClone() API provides a native, more robust alternative.
Benefits of structuredClone() include:
Native API with better performance
Proper handling circular references
Support for more data types (Date, RegExp, Map, Set, ArrayBuffer, etc.)
Meaningful thrown errors for non-cloneable values
This rule reports on any JSON.parse(JSON.stringify()) that can be replaced with structuredClone().
An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON.
JSON.parse(text: string, reviver?:(this:any, key:string, value:any)=> any): any
Converts a JavaScript Object Notation (JSON) string into an object.
@param ― text A valid JSON string.
@param ― reviver A function that transforms the results. This function is called for each member of the object.
If a member contains nested objects, the nested objects are transformed before the parent object is.
@throws ― {SyntaxError} If text is not valid JSON.
parse(
var JSON:JSON
An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
Converts a JavaScript value to a JavaScript Object Notation (JSON) string.
@param ― value A JavaScript value, usually an object or array, to be converted.
@param ― replacer A function that transforms the results.
@param ― space Adds indentation, white space, and line break characters to the return-value JSON text to make it easier to read.
@throws ― {TypeError} If a circular reference or a BigInt value is found.
stringify(
const obj:any
obj));
function
functiondeepCopy<T>(value:T):T
deepCopy<
function(typeparameter)TindeepCopy<T>(value:T):T
T>(
value: T
value:
function(typeparameter)TindeepCopy<T>(value:T):T
T):
function(typeparameter)TindeepCopy<T>(value:T):T
T {
return
var JSON:JSON
An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
JSON.
JSON.parse(text: string, reviver?:(this:any, key:string, value:any)=> any): any
Converts a JavaScript Object Notation (JSON) string into an object.
@param ― text A valid JSON string.
@param ― reviver A function that transforms the results. This function is called for each member of the object.
If a member contains nested objects, the nested objects are transformed before the parent object is.
@throws ― {SyntaxError} If text is not valid JSON.
parse(
var JSON:JSON
An intrinsic object that provides functions to convert JavaScript values to and from the JavaScript Object Notation (JSON) format.
If your project relies on the different, older semantics of JSON, you might need to disable this rule.
You might consider using Flint disable comments and/or configuration file disables for those specific situations instead of completely disabling this rule.