All documents

ModelNormalizerApp

spicegrinder-icon

© 2026 Obsvra. This document describes SpiceGrinder and is provided to help you evaluate and use it. It is not a license to reproduce, adapt, or use this material to build a competing product or service. Full terms: the SpiceGrinder EULA.

NAME

ModelNormalizerApp — flatten <Import> references into one self-contained model (Pro)

SYNOPSIS

java -cp spicegrinder.jar com.obsvra.spicegrinder.pro.tools.ModelNormalizerApp [options] model.xml|model.json|-

On a jpackage Pro install:

normalize [options] model.xml|model.json|-

Not present in a Free build — ModelNormalizerApp lives in the pro.tools package and has no Free-tier equivalent.

DESCRIPTION

ModelNormalizerApp reads a single model file and writes out an equivalent model with every <Import> — including nested ones — resolved and inlined. Imported node names are prefixed the same way a normal load would register them (the <Import> node’s own name= or prefix= attribute, falling back to "import" if neither is set), and every reference to an Import’s own alias is rewritten to point at the real, now-inlined node. An imported file’s <declare>s are settled first, with the <Import>’s override attributes: its nodes carry the values, not $name references. A collaborate.<role> attribute (a StateRead’s store) is prefixed like an <input>. The top model’s own <declare>s stay in the output, but an <Import> attribute that uses one gets its value when the file is flattened, so apply any --declare before flattening.

The output has no remaining <Import> elements and no dependency on relative file paths — it’s a single, self-contained file that can be moved, shared, or submitted elsewhere without carrying its library dependencies along separately.

The model argument may be - instead of a path, meaning “read this model from stdin” — the same sentinel ModelValidatorApp/ModelAnalyzerApp/Grind already accept. Content is sniffed as XML or JSON, matching those tools; Compact (.sgm) format needs a real file, since it has no content signature to sniff. There is no model directory to anchor relative <Import> paths at in that case, so they resolve against the current working directory instead (or the folder given with --model-dir DIR), same as the other tools’ stdin handling.

The actual flattening logic (ModelNormalizer.flatten) is also directly callable from Java against an in-memory model string; this CLI is a thin wrapper around it. The typical caller is something that needs to flatten a model just before submitting it elsewhere — e.g. a Service API client — not the Service API itself, which never needs to do this on its own behalf.

OPTIONS

OptionMeaning
--out PATHWrite the flattened model to a file (default: stdout).
--quietSuppress the progress banner lines normally written to stderr.
-h, --helpPrint usage and exit.
--versionPrint the version (e.g. 1.0.0 (Build 1)) and exit.
--jsonWrap the output (stdout or --out) in a JSON object with metadata instead of writing the flattened model text alone. See OUTPUT (JSON) below.
--local-root DIRUse DIR as the model’s local root for this run, ahead of project.root, a .spicegrinder-root marker and the Git work-tree top. A relative data file (a FlatFile file, an Email wordListFile) not beside the model is looked for there before the working directory, and a relative <Import> after the model’s folder; each must stay inside the folder it was found in. The desktop app passes its Local root setting this way. See FlatFile and the Model File Format Reference.
--model-dir DIRWith - (stdin): resolve the model’s relative paths (<Import> files and data files) as if it were saved in DIR. The desktop app passes an edited model’s own folder this way.

OUTPUT (JSON)

Without --json, the destination (stdout or --out) receives the flattened model text alone — nothing else. With --json, that same destination receives one JSON object instead:

{
  "model": "/abs/path/model.xml",
  "output": "-",
  "flattened": "<the flattened model text>",
  "bytes": 4821,
  "imports": [
    {
      "importNode": "Lib",
      "file": "const-lib.xml",
      "resolvedPath": "/abs/const-lib.xml",
      "prefix": "lib",
      "root": "lib.Const",
      "nodes": ["lib.Const", "lib.Other"],
      "imports": []
    }
  ],
  "error": null
}

output is "-" for stdout, or the resolved --out path. bytes is the flattened text’s own UTF-8 byte length. imports gives provenance for every top-level <Import> in the model, so a caller (e.g. a GUI showing an <Import> node’s contents inline) can see what each one contributed without re-parsing flattened: importNode is the Import’s own name= attribute exactly as written; file and resolvedPath are its file= attribute unresolved and resolved to an absolute path; prefix is the prefix actually applied to its nodes (prefix=, else name=, else "import"); root and nodes are that import’s root node and every node it contributed — including nested imports’ nodes — as their final, fully-prefixed names (every enclosing import’s prefix applied, e.g. outer.inner.X); nested <Import>s inside an imported file appear, in the same shape, inside that entry’s own imports array. A nested entry additionally carries flatName: the fully-prefixed name its own importNode would have had if it were an ordinary node, useful for matching a nested entry against flattened at any depth without recomputing the prefix chain by hand — a top-level entry omits flatName, since nothing ever prefixes the top document’s own names. No third output destination is introduced — whatever would have received the raw flattened text receives this JSON object instead. On failure (model file not found, or normalization failed), the same destination receives a leaner object instead: {"model": "...", "error": "<message>"} — no imports key.

The MCP server’s normalize_model tool (Pro builds) returns this same object from inline model text, less model and output; see McpServerApp.md.

-h/--help/--version output and bad-argument errors (exit code 2) always stay plain text, unaffected by --json.

EXIT STATUS

CodeMeaning
0Normalization succeeded.
1Model file not found, or normalization failed (e.g. an <Import> couldn’t be resolved).
2Bad arguments — missing required value, unrecognized option, or not exactly one model file given.

EXAMPLES

Flatten a model to stdout:

java -cp spicegrinder.jar com.obsvra.spicegrinder.pro.tools.ModelNormalizerApp model.xml

Flatten to a file, no progress banner:

normalize --quiet --out flattened.xml model.xml

Get a machine-readable result for a script or agent to parse:

normalize --json --quiet model.xml

Flatten a model piped in on stdin (relative <Import> paths resolve against the current directory):

cat model.xml | normalize -

SEE ALSO

Model-File-Format-Reference.md (<Import> semantics), Service-API-Reference.md, ComponentLibraryApp(1)