Deterministic and safely JSON.stringify to quickly serialize JavaScript objects
90
Evaluation — 90%
↑ 1.08xAgent success when using this tile
Build a utility that safely serializes JavaScript objects containing circular references to JSON strings.
Your task is to implement a function that serializes JavaScript objects to JSON format, with special handling for circular references. Unlike JSON.stringify() which throws a TypeError when encountering circular references, your implementation should detect and handle them gracefully.
The function should:
"[Circular]" by default@generates
/**
* Serializes a JavaScript object to a JSON string, handling circular references.
* @param {any} value - The value to serialize
* @param {string|null} [circularValue] - Optional custom value to use for circular references
* @returns {string} The JSON string representation
*/
function serialize(value, circularValue) {
// Implementation here
}
module.exports = { serialize };"[Circular]" @test"[Circular]" @testcircularValue set to "CYCLE", the circular property should be replaced with "CYCLE" @testcircularValue set to null, the circular property should be replaced with JSON null @testProvides safe JSON serialization with circular reference handling.
@satisfied-by
Install with Tessl CLI
npx tessl i tessl/npm-safe-stable-stringifydocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10