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. loadJSON

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 T

Examples

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

See Also

  • loadText - Load as raw text
  • load - Load as ArrayBuffer
Previous
load
Next
loadLocal