Skip to content

Path Syntax

frosxt edited this page Jan 18, 2026 · 1 revision

Path Syntax

JsonConfig uses a dot-notation syntax to traverse the JSON hierarchy. This allows you to read and modify deeply nested values without retrieving intermediate objects.

Dot Notation

The dot . separates keys in a JSON object.

JSON:

{
  "server": {
    "database": {
      "host": "localhost"
    }
  }
}

Access:

String host = config.getString("server.database.host");

Array Access

You can access array elements using brackets [index].

JSON:

{
  "users": [
    { "name": "Alice", "id": 1 },
    { "name": "Bob", "id": 2 }
  ]
}

Access:

// Get the name of the first user
String firstUser = config.getString("users[0].name"); // "Alice"

// Helper method to get the ID of the second user
int secondId = config.getInt("users[1].id"); // 2

Relative Paths

When working with a JsonSection (a subsection of the config), paths are relative to that section.

JsonSection dbSection = config.getConfigurationSection("server.database");

// access 'host' relative to 'server.database'
String host = dbSection.getString("host"); 

Clone this wiki locally