Skip to content

Bun soporta nativamente las importaciones de .json.

json
{
  "name": "bun",
  "version": "1.0.0",
  "author": {
    "name": "John Dough",
    "email": "john@dough.com"
  }
}

Importa el archivo como cualquier otro archivo de código fuente.

ts
import data from "./package.json";

data.name; // => "bun"
data.version; // => "1.0.0"
data.author.name; // => "John Dough"

Bun también soporta la sintaxis de Atributos de Importación y Módulos JSON.

ts
import data from "./package.json" with { type: "json" };

data.name; // => "bun"
data.version; // => "1.0.0"
data.author.name; // => "John Dough"

Consulta Documentación > Runtime > TypeScript para más información sobre cómo usar TypeScript con Bun.

Bun por www.bunjs.com.cn editar