Skip to main content

Unifying Config from Multiple Formats

Real systems end up with config scattered across formats — a YAML deploy manifest, a TOML tool config, a JSON API response — and the usual fix is converting everything to one format up front, or writing a parser per format downstream. Format is just an import detail here, not a boundary: whatever comes in lands in the same graph and gets read the same way, regardless of where it started.

Two Formats, Same Field Access

step1.stof
#[main]
fn main() {
  const from_yaml = new {};
  parse("name: growth\nlimit: 100000", from_yaml, "yaml");

  const from_toml = new {};
  parse('name = "starter"\nlimit = 10000', from_toml, "toml");

  pln(from_yaml.name, from_yaml.limit);
  pln(from_toml.name, from_toml.limit);
}
Output

Merging Three Sources Into One

unify.stof
plans: []

#[main]
fn main() {
  const from_yaml = new {};
  parse("name: growth\nlimit: 100000", from_yaml, "yaml");
  self.plans.push_back(from_yaml);

  const from_toml = new {};
  parse('name = "starter"\nlimit = 10000', from_toml, "toml");
  self.plans.push_back(from_toml);

  const from_json = new {};
  parse('{"name": "enterprise", "limit": 1000000}', from_json, "json");
  self.plans.push_back(from_json);

  let total = 0;
  for (const plan: obj in self.plans) {
      total += plan.limit;
  }
  pln(total);
}
Output

One loop, summing a field that came from three different source formats — nothing in it knows or cares which one any given plan started as. The translation layer that would normally exist between "the format we use" and "the format they use" just isn't there to maintain.