spark.loadJSON
function loadJSON<T = unknown>(path: string): Promise<T>Load a JSON file from torchjs.org and parse it.
Loads a file as text, parses it as JSON, and returns the result. You can provide a type parameter for TypeScript type safety.
Common use cases:
- Loading model configuration files
- Loading training hyperparameters
- Loading metadata and annotations
- Loading manifests (datasets, models, etc.)
JSON files should be valid JSON format. If parsing fails, a descriptive error message will indicate the parse error.
Parameters
pathstring- File path in format "username/project/filename" or "username/project/path/to/file"
Returns
Promise<T>– Promise that resolves to the parsed JSON object of type TExamples
// Load model configuration with type safety
interface ModelConfig {
layers: number;
hidden_size: number;
activation: string;
}
const config = await spark.loadJSON<ModelConfig>('kasumi/gpt2/config.json');
console.log(`Model has ${config.layers} layers`);
// Load without specific type (uses 'unknown')
const metadata = await spark.loadJSON('kasumi/mnist/metadata.json');
// Load dataset manifest
const manifest = await spark.loadJSON('kasumi/mnist/torch.json');