Skip to content

O Bun suporta nativamente imports de .json.

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

Importe o arquivo como qualquer outro arquivo de código.

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

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

O Bun também suporta a sintaxe Import Attributes e JSON modules.

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

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

Consulte Docs > Runtime > TypeScript para mais informações sobre usar TypeScript com Bun.

Bun by www.bunjs.com.cn edit