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-10/

High-Volume Data Serialization Service

Overview { .overview }

Build a data serialization service that handles high-volume logging scenarios efficiently. The service needs to process various types of data structures while maintaining high performance, especially when dealing with large datasets and different serialization requirements.

Requirements { .requirements }

Core Functionality

  1. Basic Serializer

    • Create a serializer that can handle standard JavaScript objects and arrays
    • Ensure deterministic output where keys are sorted alphabetically
    • Support formatted output with indentation for readability
  2. Optimized Large Object Handler

    • Implement functionality to serialize objects with many properties (e.g., 500+ keys)
    • Use appropriate strategies based on object size for optimal performance
  3. Specialized Serialization Configurations

    • Create a fast configuration optimized for simple objects without transformations
    • Create a configuration that supports custom value transformations via callback functions
    • Create a configuration that only serializes whitelisted properties from an array

Implementation Guidelines

  • Implement the serializer in src/serializer.js
  • Export a main serialize function that handles all cases
  • Export a createSerializer function that creates optimized serializers for specific scenarios
  • All exports should be available as named exports

Test Cases

Implement test cases in src/serializer.test.js:

Test 1: Basic Object Serialization { .test }

const data = { name: "Alice", age: 30, city: "NYC" };
const result = serialize(data);
// Should produce deterministic JSON string with sorted keys

Test 2: Large Object Performance { .test }

const largeObject = {};
for (let i = 0; i < 500; i++) {
  largeObject[`key${i}`] = `value${i}`;
}
const result = serialize(largeObject);
// Should efficiently serialize with sorted keys

Test 3: Specialized Configurations { .test }

// Fast configuration - no transformations, no indentation
const fastSerializer = createSerializer({ mode: 'fast' });
const result1 = fastSerializer({ x: 1, y: 2 });

// Configuration with custom value transformation
const transformSerializer = createSerializer({
  mode: 'transform',
  transformer: (key, value) => typeof value === 'string' ? value.toUpperCase() : value
});
const result2 = transformSerializer({ name: "alice", age: 30 });

// Configuration with property whitelist
const selectiveSerializer = createSerializer({
  mode: 'selective',
  properties: ['name', 'age']
});
const result3 = selectiveSerializer({ name: "Bob", age: 25, city: "LA" });
// Should only include name and age

Dependencies { .dependencies }

safe-stable-stringify { .dependency }

Provides safe and performant JSON serialization with deterministic output.

Constraints { .constraints }

  • Use JavaScript (Node.js environment)
  • Focus on performance optimization
  • Ensure deterministic output for consistent results
  • Handle edge cases gracefully

Success Criteria { .success_criteria }

  • All test cases pass
  • Serialization handles objects with 500+ properties efficiently
  • Different serialization modes work correctly
  • Output is deterministic and properly formatted

Install with Tessl CLI

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

tile.json