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 savedExamples
// 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);