Skip to main content
torch.js has not been released yet.
torch.js logotorch.js logotorch.js
PlaygroundContact
Login
Documentation
IntroductionType SafetyTensor ExpressionsTensor IndexingEinsumEinopsAutogradTraining a ModelProfiling & MemoryPyTorch MigrationBest PracticesRuntimesPerformancePyTorch CompatibilityBenchmarksDType Coverage
torch.js· 2026
LegalTerms of UsePrivacy Policy
/
/
  1. docs
  2. Spark
  3. spark
  4. saveJSON

spark.saveJSON

function saveJSON(path: string, data: unknown): Promise<void>

Save data as JSON to torchjs.org.

Convenience function that serializes data to JSON and saves it as a file. JSON is formatted with 2-space indentation for readability.

Use this for:

  • Saving configuration and hyperparameters
  • Saving metadata and annotations
  • Saving training logs and metrics
  • Saving any structured data
JSON output uses 2-space indentation. If you need custom JSON formatting, use save with JSON.stringify directly.

Parameters

pathstring
File path in format "username/project/filename" or "username/project/path/to/file"
dataunknown
Data to serialize as JSON (must be JSON-serializable)

Returns

Promise<void>– Promise that resolves when file is saved

Examples

// Save model configuration
await spark.saveJSON('kasumi/gpt2/config.json', {
  layers: 12,
  hidden_size: 768,
  attention_heads: 12,
  activation: 'gelu'
});

// Save training metrics
const metrics = {
  epoch: 10,
  loss: 0.245,
  accuracy: 0.968,
  timestamp: new Date().toISOString()
};
await spark.saveJSON('kasumi/project/metrics.json', metrics);

See Also

  • save - Save raw ArrayBuffer or string
  • loadJSON - Load and parse JSON files
Previous
save
Next
saveLocal