Compendium Pack JSON Definition

To define a valid Compendium pack in a JSON manifest file include the following object structure inside the packs array.

"packs": [
    {
      "name": "pack-name",
      "label": "Pack Title",
      "system": "system-name",
      "path": "./packs/pack-name.db",
      "entity": "Item"
    },
]

The elements of this data structure are defined as follows:

name

The compendium pack name - this should be a unique lower-case string with no special characters.

label

The compendium pack label - this should be a human readable string label which is displayed in the Compendium sidebar in-game.

system

Since you are creating compendium content specifically for your system, be sure to reference that the content inside each compendium pack requires the system by providing the system name that you chose.

module

The module attribute of each compendium pack designates which content module provided the pack, since this pack is coming from the system itself we can once again provide the system name.

path

The path for each compendium pack should designate a database file with the .db extension. As a best practice, I recommend placing these database files within the packs subdirectory. You do not need to create these files yourself. If a system includes a compendium pack, the database file for that pack will be created automatically when the system is loaded, if it does not already exist.

entity

Each compendium pack must designate a specific Entity type that it contains. Valid entities include Actor, Item, or Scene.

system

Each compendium pack may optionally specify a string or Array of strings which identifies the game system or systems for which its included content is appropriate.

Bulk Importing of Compendium Content

A relatively common desire for module or system developers is to bulk import external content to create a compendium pack. There are several ways to do this, but the recommended approach is to use the API to handle creation of your compendium entries from structured data. The following code block provides an example of importing Actor data from an external JSON file and using that data to populate a compendium pack.

// Reference a Compendium pack by it's callection ID
const pack = game.packs.find(p => p.collection === `${moduleName}.${packName}`);

// Load an external JSON data file which contains data for import
const response = await fetch("worlds/myworld/data/import.json");
const content = await response.json();

// Create temporary Actor entities which impose structure on the imported data
const actors = Actor.createMany(content, {temporary: true});

// Save each temporary Actor into the Compendium pack
for ( let a of actors ) {
  await pack.importEntity(a);
  console.log(`Imported Actor ${a.name} into Compendium pack ${pack.collection}`);
}