Deterministic and safely JSON.stringify to quickly serialize JavaScript objects
90
Evaluation — 90%
↑ 1.08xAgent success when using this tile
Create a utility that generates consistent hash values from JavaScript objects for caching purposes.
Build a function generateObjectHash(obj) that:
The generated string should be deterministic - objects with identical content must always produce the same output, even if their properties were defined in different orders.
@generates
/**
* Generates a deterministic string representation of an object for hashing.
* @param {Object} obj - The object to generate a hash string for
* @returns {string} A deterministic string representation
*/
function generateObjectHash(obj) {}
module.exports = { generateObjectHash };{name: "Alice", age: 30} and object {age: 30, name: "Alice"}, both produce identical output @test{user: {id: 1, name: "Bob"}} and {user: {name: "Bob", id: 1}}, both produce identical output @test{z: 3, a: 1, m: 2}, the output maintains alphabetical key order @testProvides deterministic JSON serialization with sorted keys.
@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