Otter
Blueprints
Otter
Upstream Blueprint Tested
File-Backed JSON Application Settings Blueprint
Load persistent JSON configuration with default fallbacks and write updates safely.
Architecture & Runtime Preview
Otter >=1.0.1Uses file-helpers.readJsonObject to parse existing configuration safely, and file-helpers.writeJsonObject to save modified properties.
- 1Default Settings (input)
- 2Load or Fallback (pack-call: file-helpers.readJsonObject)
- 3Save Settings (pack-call: file-helpers.writeJsonObject)
Source Code (4 files)
{
"schemaVersion": 1,
"id": "otter-official/file-settings",
"version": "1.0.0",
"title": "File-Backed JSON Application Settings",
"summary": "Load persistent JSON configuration with default fallbacks and write updates safely.",
"targets": ["console", "desktop"],
"requiresOtter": ">=1.0.1",
"packs": [
{ "id": "otter-official/file-helpers", "version": "1.0.1" }
],
"configuration": [
{
"id": "settingsFileName",
"label": "Settings File Name",
"type": "text",
"default": "settings.json",
"description": "Path to persistent JSON settings file"
}
],
"nodes": [
{
"id": "defaults",
"title": "Default Settings",
"kind": "input",
"inputs": [],
"outputs": [{ "name": "config", "type": "object" }],
"description": "Fallback configuration values"
},
{
"id": "loadConfig",
"title": "Load or Fallback",
"kind": "pack-call",
"capability": "file-helpers.readJsonObject",
"inputs": [
{ "name": "path", "type": "file", "required": true }
],
"outputs": [{ "name": "loadedConfig", "type": "object" }],
"description": "Read settings file from disk"
},
{
"id": "saveConfig",
"title": "Save Settings",
"kind": "pack-call",
"capability": "file-helpers.writeJsonObject",
"inputs": [
{ "name": "path", "type": "file", "required": true },
{ "name": "data", "type": "object", "required": true }
],
"outputs": [{ "name": "success", "type": "boolean" }],
"description": "Persist configuration back to disk"
}
],
"edges": [
{ "from": "loadConfig.loadedConfig", "to": "saveConfig.data", "label": "active config" }
],
"generatedFiles": [
{
"path": "src/settings.ot",
"template": "templates/settings.ot.tmpl"
}
],
"explanations": {
"beginner": "Reads your application39;s settings.json file. If the file does not exist yet, it creates one with default values.",
"intermediate": "Uses file-helpers.readJsonObject to parse existing configuration safely, and file-helpers.writeJsonObject to save modified properties.",
"advanced": "Safely encapsulates file read/write I/O with JSON serialization and disk error fallback handling."
},
"tests": [
"tests/test.ot"
]
}
# Generated by Otter Blueprint: otter-official/file-settings 1.0.0
# Standard editable Otter 1.0.1 source code
use "${import:otter-official/file-helpers}"
configPath is "${settingsFileName}"
defaultConfig has
theme is "dark"
autosave is true
fontSize is 14
.
# Step 1: Read or initialize settings
settings is readJsonObject configPath
if settings is gone
say "No settings file found. Initializing defaults..."
writeJsonObject configPath defaultConfig
settings is defaultConfig
.
say "Active configuration:"
say " Theme:" theme of settings
say " Autosave:" autosave of settings
say " Font Size:" fontSize of settings
# Integration tests for file-settings Blueprint
use "../../../../packs/otter-official/file-helpers/src/main.ot"
testSettingsFile is "test_suite_settings.json"
cfg has
app is "Otter Studio"
version is 1
.
# Test 1: Write JSON settings
writeOk is writeJsonObject testSettingsFile cfg
if writeOk is true
say "test 1 passed: settings written"
.
# Test 2: Read JSON settings
readCfg is readJsonObject testSettingsFile
if app of readCfg is "Otter Studio"
say "test 2 passed: settings read accurately"
.
delete file testSettingsFile
say "All file-settings tests passed."
# Demo for file-settings Blueprint
use "../../../../packs/otter-official/file-helpers/src/main.ot"
say "=== File Settings Blueprint Demo ==="
demoFile is "test_demo_settings.json"
defaults has
theme is "light"
volume is 80
.
writeJsonObject demoFile defaults
loaded is readJsonObject demoFile
say "Theme from disk:" theme of loaded
say "Volume from disk:" volume of loaded
delete file demoFile
say "Cleaned up demo file."
Installation & Usage
otter blueprint explain otter-official/file-settings
otter blueprint apply otter-official/file-settings --project ./my-app
Reads your application's settings.json file. If the file does not exist yet, it creates one with default values.