Skip to main content
Bun can parse JSON files directly.

Read JSON File

const file = Bun.file("data.json");
const data = await file.json();
console.log(data);

With Type Safety

interface User {
  name: string;
  email: string;
}

const file = Bun.file("users.json");
const users: User[] = await file.json();

Error Handling

try {
  const file = Bun.file("config.json");
  const config = await file.json();
} catch (error) {
  console.error("Invalid JSON:", error);
}
See File I/O for complete documentation.

Build docs developers (and LLMs) love