Chapter 1: Understanding BEJSON Fundamentals
The Core Principle: Positional Integrity (The Spreadsheet Analogy)
To truly understand BEJSON, imagine your data organized as a simple spreadsheet.
In this analogy:
- The
Fieldsarray represents the header row of your spreadsheet. Each object inFieldsis a column definition, specifying the name and type of data expected for that column. - The
Valuesarray represents all the data rows. Each inner array withinValuesis a single record, with each element corresponding to a specific column defined in theFieldsarray.
Consider this BEJSON structure:
{
"Format": "BEJSON",
"Format_Version": "104",
"Format_Creator": "Elton Boehnen",
"Records_Type": ["User"],
"Fields": [
{"name": "id", "type": "string"},
{"name": "username", "type": "string"},
{"name": "email", "type": "string"},
{"name": "is_active", "type": "boolean"}
],
"Values": [
["user-001", "alice", "alice@example.com", true],
["user-002", "bob", "bob@example.com", false],
["user-003", "charlie", null, true]
]
}
This BEJSON structure maps directly to a spreadsheet like this:
| id | username | is_active | |
|---|---|---|---|
| user-001 | alice | alice@example.com | true |
| user-002 | bob | bob@example.com | false |
| user-003 | charlie | null | true |
Notice how:
- The
Fieldsarray defines four columns (id,username,email,is_active). - Each array within
Valueshas exactly four elements, aligning perfectly with the four fields. - For
user-003, theemailfield isnull. This is critical. Instead of omitting the field and shiftingtrueinto theemailcolumn,nullexplicitly indicates the absence of data for that specific column in that record, maintaining the integrity of the data matrix. This prevents misinterpretation and ensures thatis_activefor "charlie" is always found at the fourth position.
This strict positional integrity, enforced by matching Fields and Values lengths and the use of nulls, is fundamental to BEJSON's reliability. It guarantees that any tool parsing the data can always determine the purpose of a value based solely on its position, without needing complex lookups or error-prone heuristics.
BEJSON provides several format versions tailored for different use cases. In this guide, we will focus on BEJSON 104 for general single-entity data storage and BEJSON 104a for lightweight metadata and configuration.
BEJSON 104: The Single-Entity Data Store
BEJSON 104 is the workhorse for storing collections of similar data entities. It is designed for rich data structures where each file typically represents a single "table" or "collection" of records.
Key characteristics of BEJSON 104:
Records_Type: This must contain exactly one string, which serves as the name for the type of entity stored in the file (e.g.,["User"],["Product"]).- Header Constraints: Beyond the mandatory top-level keys,
BEJSON 104does not permit custom top-level headers, with the sole exception of the optionalParent_Hierarchykey, which is used in multi-file database contexts like MFDB. This restriction keepsBEJSON 104focused purely on record data. - Type Support:
BEJSON 104fully supports all JSON types, including complexarrayandobjectstructures within itsValues. This flexibility allows for the representation of highly structured and nested data within individual records.
Valid BEJSON 104 Schema Example
Let's consider a simple inventory list using BEJSON 104:
{
"Format": "BEJSON",
"Format_Version": "104",
"Format_Creator": "Elton Boehnen",
"Records_Type": ["Product"],
"Fields": [
{"name": "product_id", "type": "string"},
{"name": "name", "type": "string"},
{"name": "description", "type": "string"},
{"name": "price", "type": "number"},
{"name": "tags", "type": "array"},
{"name": "details", "type": "object"}
],
"Values": [
["PROD001", "Laptop", "High-performance laptop", 1200.00, ["electronics", "computer"], {"brand": "TechCorp", "weight_kg": 1.8}],
["PROD002", "Mouse", "Ergonomic wireless mouse", 25.50, ["electronics", "accessory"], {"brand": "ErgoGear", "color": "black"}],
["PROD003", "Keyboard", null, 75.00, ["electronics"], null]
]
}
In this example, you can see PROD003 demonstrates null for description and details, maintaining alignment. We also use complex types like tags (an array of strings) and details (an object) within the Values array, which BEJSON 104 readily supports.
BEJSON 104a: Metadata and Configuration
While BEJSON 104 is for transactional data, BEJSON 104a is optimized for lightweight metadata, configuration settings, or lookup tables where simplicity and rapid parsing are paramount. It imposes stricter data type limitations and allows for file-level custom metadata.
Key characteristics of BEJSON 104a:
Records_Type: LikeBEJSON 104, it must contain exactly one string. This typically names the type of configuration or metadata (e.g.,["Settings"],["AssetMap"]).- Type Restrictions: This is a critical distinction.
BEJSON 104astrictly forbids complex data types (array,object) within itsValuesarray. Only primitive types are allowed:string,integer,number, andboolean. This restriction ensures that104afiles are always lightweight and can be parsed with minimal overhead, making them ideal for system configurations or simple key-value stores. - Custom Headers: Unlike
BEJSON 104,BEJSON 104aexplicitly permits custom top-level headers. These headers must usePascalCase(e.g.,Project_Name,Deployment_Zone) and are intended to provide file-level metadata that applies to the entire document, rather than to individual records.
Valid BEJSON 104a Schema Example
Here's an example of BEJSON 104a used for application settings:
{
"Format": "BEJSON",
"Format_Version": "104a",
"Format_Creator": "Elton Boehnen",
"Records_Type": ["AppSettings"],
"Application_Name": "Content Hub",
"Deployment_Zone": "EastUS",
"Is_Debug_Mode": true,
"Fields": [
{"name": "setting_key", "type": "string"},
{"name": "setting_value", "type": "string"},
{"name": "is_critical", "type": "boolean"}
],
"Values": [
["theme", "dark", false],
["language", "en-US", false],
["log_level", "INFO", true],
["cache_enabled", "true", true]
]
}
In this BEJSON 104a example, observe the custom top-level headers like Application_Name, Deployment_Zone, and Is_Debug_Mode. These provide context for the entire settings file. Within the Values array, all entries are primitive types (string, boolean), strictly adhering to the 104a specification. Notice cache_enabled's value is "true" (a string), not true (a boolean), because setting_value is defined as a string type in Fields. This demonstrates the importance of adhering to declared types.
By understanding these fundamental principles, especially positional integrity, and the distinct roles of BEJSON 104 and BEJSON 104a, you are well-equipped to begin structuring your data effectively within the BEJSON ecosystem.