CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-safe-stable-stringify

Deterministic and safely JSON.stringify to quickly serialize JavaScript objects

90

1.08x

Evaluation90%

1.08x

Agent success when using this tile

Overview
Eval results
Files

task.mdevals/scenario-8/

Object Hash Generator

Create a utility that generates consistent hash values from JavaScript objects for caching purposes.

Requirements

Build a function generateObjectHash(obj) that:

  1. Takes any JavaScript object as input
  2. Returns a consistent string representation that can be used for hashing
  3. Ensures that two objects with the same properties (regardless of insertion order) produce identical string representations
  4. Works correctly with nested objects

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.

Implementation

@generates

API

/**
 * 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 };

Test Cases

  • Given object {name: "Alice", age: 30} and object {age: 30, name: "Alice"}, both produce identical output @test
  • Given nested object {user: {id: 1, name: "Bob"}} and {user: {name: "Bob", id: 1}}, both produce identical output @test
  • Given object {z: 3, a: 1, m: 2}, the output maintains alphabetical key order @test

Dependencies { .dependencies }

safe-stable-stringify { .dependency }

Provides deterministic JSON serialization with sorted keys.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-safe-stable-stringify

tile.json