Overview
boilerplate uses JSON schemas to describe the structure
expected for each database type. This vignette documents those schemas
for users who want to inspect, validate, or generate database files
outside R.
Methods Database Schema
Methods entries contain standardised text with template variables.
Entry Variants
Methods can have multiple text variants:
{
"statistical": {
"regression": {
"linear": {
"default": "We used linear regression to analyse {{outcome}}.",
"large": "We employed ordinary least squares linear regression to examine the relationship between {{predictors}} and {{outcome}}. Model assumptions were examined, including...",
"brief": "Linear regression was used."
}
}
}
}Measures Database Schema
Measures entries describe variables and instruments used in research.
Complete Example
{
"psychological": {
"anxiety": {
"gad7": {
"name": "gad7",
"description": "Generalised Anxiety Disorder 7-item scale",
"type": "ordinal",
"items": 7,
"range": [0, 21],
"values": [0, 1, 2, 3],
"value_labels": ["Not at all", "Several days", "More than half the days", "Nearly every day"],
"cutoffs": {
"mild": 5,
"moderate": 10,
"severe": 15
},
"reference": "@spitzer2006brief",
"keywords": ["anxiety", "screening", "GAD-7"],
"scoring": {
"type": "sum",
"interpretation": {
"0-4": "Minimal anxiety",
"5-9": "Mild anxiety",
"10-14": "Moderate anxiety",
"15-21": "Severe anxiety"
}
}
}
}
}
}Required Fields
- name: Unique identifier (string, alphanumeric + underscore)
- description: Full description (string, min 10 characters)
- type: One of: “continuous”, “categorical”, “ordinal”, “binary”
Template Database Schema
Template variables for substitution:
Schema Validation
JSON Schema Files
Located in inst/examples/json-poc/schema/: -
measures_schema.json: Formal schema for measures -
methods_schema.json: Formal schema for methods
Validation in R
# Validate a JSON database
boilerplate::validate_json_database(
json_file = "my_database.json",
schema_file = "measures_schema.json"
)Migration from RDS
Converting RDS to JSON
# Single category
boilerplate_rds_to_json(
rds_file = "measures_db.rds",
json_file = "measures_db.json"
)
# Unified database
boilerplate_migrate_to_json(
rds_file = "boilerplate_unified.rds",
output_dir = "data/json/"
)Format Differences
JSON Format (default)
- Text-based
- Sufficient for every data shape the package uses (strings, lists, numbers)
- Human-readable
- Cross-platform
- Safe to load: JSON deserialisation cannot execute code
RDS Format (not written by package APIs)
- Binary R object
- Preserves R-specific types that the package does not use
- Not human-readable
- Platform-specific
- Code-execution vector on load:
readRDS()can invoke attacker code through object hooks and class attributes. Package APIs no longer write RDS; reading is retained only to support migration of existing trusted databases.
Best Practices
File Organisation
project/
├── data/
│ ├── boilerplate_unified.json # Single unified file
│ └── categories/ # Or separate files
│ ├── methods.json
│ ├── measures.json
│ └── results.json
Naming Conventions
- Keys: Use lowercase with underscores
- Categories: Descriptive, hierarchical
- Measures: Include instrument abbreviation
Examples
Adding a Methods Entry with Variants
{
"sampling": {
"random": {
"default": "Participants were randomly selected from {{population}}.",
"large": "We employed a stratified random sampling approach. The {{population}} was first divided into {{strata}} strata based on {{stratification_var}}. Within each stratum, participants were randomly selected using a random number generator with seed {{seed}} for reproducibility.",
"brief": "Random sampling was used.",
"reference": "@cochran1977sampling"
}
}
}