Skip to content

Create a Module

0xMaxLab edited this page Mar 16, 2026 · 4 revisions

RichJSON is highly extensible, allowing you to create custom modules to handle game-specific logic and data transformations.


To create a module, instantiate the RichJsonModule class and define your commands.

addCommand(name, func, [ignores])

Adds a standard command resolved during the initial JSON read.

addLateApply(name, func, [ignores])

Adds a command resolved during the Late Applying phase (after the initial structure is built).

Command Function Signature

All command functions receive the following parameters: function(root, current, command, member, address, name)

Parameter Description
root The root object (e.g., the file or game object).
current The object or array currently being resolved.
member The current value (string/object) being processed.
address The internal RichJSON address path.
name The name of the current member.

📦 Lifecycle Management

Registering a module makes it available, but you must Include it to activate its commands.

  • registerModule(module): Stores the module in the registry.
  • includeModule(name): Activates the module's commands. Note: You cannot override built-in commands.
  • excludeModule(name): Deactivates the module's commands without removing it from the registry.
  • unregisterModule(name): Removes the module entirely. Fails if the module is currently included.
  • isModuleRegistered(name): Checks if a module exists in the registry.

💡 Example Implementation

import * as RichJson from "@rjson/parser"
// 1. Define and Register
const myModule = new RichJsonModule("my_module")
    .addCommand("ilog", (root, current, cmd, member) => {
         console.log(member);
         return member;
    })
    .addLateApply("wlog", (root, current, cmd, member) => {
         console.warn(member);
         return member;
    });

RichJson.registerModule(myModule);

// 2. Activate
RichJson.includeModule("my_module");

Author’s Recommendation: next read Keep Key Command

Clone this wiki locally