Skip to content

Bun supporta nativamente gli import .json.

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

Importa il file come qualsiasi altro file sorgente.

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

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

Bun supporta anche la sintassi 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"

Vedi Docs > Runtime > TypeScript per maggiori informazioni sull'uso di TypeScript con Bun.

Bun a cura di www.bunjs.com.cn