Skip to content

Piper V2 file format

Piper V2 emits two kinds of JSON files: graph files describing designed pipelines (the user's .piper documents) and registry catalog files describing the catalog of available node types (typically engine-supplied). Both share the V2 conventions and the same version integer; their top-level shapes differ.

The format is designed to be consumed by external engines (the runtime that interprets Piper-designed pipelines) -- not just round-tripped by Piper itself. This document is the authoritative schema reference.

The writer emits "version": 3. The loader also accepts 2 and throws on any other value; every accepted file is read with the field names below.

Conventions

  • Encoding: UTF-8.
  • Top-level value: a JSON object.
  • Numeric IDs (NodeId, LinkId) are unsigned 64-bit integers. Zero is reserved as "invalid" -- never appears as a real ID.
  • Floats are standard JSON numbers. pos arrays carry IEEE-754 values; precision below ~6 significant digits is not guaranteed to round-trip identically.
  • Color values are hex strings: "#RRGGBBAA" (red high byte, alpha low byte). Alpha is mandatory -- the 6-digit #RRGGBB form is rejected. Case-insensitive on read; emitted upper-case.
  • Optional fields are omitted when empty/default -- readers must accept both absent and explicit-default values.

Top-level structure

A V2 file is a bundle of one or more pipelines. The single-pipeline case is just a bundle of one entry.

{
    "version":   3,
    "pipelines": [
        {
            "name":         "main",
            "meta":         { ... },
            "default_profile": "...",
            "nodes":        [ ... ],
            "links":        [ ... ],
            "stages":       [ ... ],
            "profiles":     [ ... ]
        }
    ]
}
Field Type Required Notes
version int yes 3 (2 is also accepted). Any other value causes the loader to throw.
pipelines array optional Each entry is a Pipeline (see below). Always written. When absent, the loader reads the top-level object itself as a single Pipeline.

Pipeline

Each entry in pipelines[] carries a complete graph plus its own metadata.

Field Type Required Notes
name string optional Free-form identifier. Used by the editor to label tabs when one file holds many pipelines. Empty/missing is allowed.
meta object optional Free-form {string: string} map. V2 does not interpret keys. Omitted when empty.
default_profile string optional Name of the profile applied at start. Absent: the first profile. A name not in profiles[] falls back to the first profile with a DefaultProfileRepaired diagnostic.
nodes array optional Defaults to [].
links array optional Defaults to [].
stages array optional Defaults to [].
profiles array optional Defaults to []. See Profile.

The deserializer throws std::runtime_error only on (a) malformed JSON or (b) an unsupported version. All other structural problems are reported as diagnostics; the graph still loads with verbatim data.

Node

{
    "id":    42,
    "type":  "Bus",
    "name":  "main_bus",
    "stage": "control",
    "pos":   [320, 180],
    "attrs": [ ... ]
}
Field Type Required Notes
id uint64 yes Stable handle; non-zero, unique within nodes.
type string yes Looked up in the registry. Unknown type -> UnknownNodeType diagnostic; node still loads.
name string optional Defaults to "". User-editable; not a stable handle.
stage string optional Defaults to "". References a stages[].name; unknown reference -> UnknownStageReference diagnostic.
pos [float, float] optional Defaults to [0, 0]. Canvas coordinates.
modes string[] optional The node's modes, without "disable". Absent means ["enable"] and is how ["enable"] is written. The loader adds any mode of the node's type the list lacks.
attrs array optional Defaults to []. See Attribute below.

Attribute

Per-instance attribute on a node. The name/data_type/role fields deliberately duplicate the registry's AttributeSpec -- the duplication is the load-time drift signal.

{
    "name":      "torque_cmd",
    "data_type": "vec3",
    "role":      "output",
    "value":     "0.0",
    "stages":    ["control"]
}

A member with values per mode:

{
    "name":           "cutoff",
    "data_type":      "float",
    "role":           "member",
    "value":          10,
    "mode_overloads": { "tight": 100, "loose": 2 }
}
Field Type Required Notes
name string yes Stable handle for PinRef::attr.
data_type string yes Type-tag string. Drift versus current registry -> AttributeDrift diagnostic.
role string yes One of "input", "output", "member", "external_input", "external_output". Other values -> SchemaError.
value typed optional Member values (PID gains, default sample rate, etc.). Encoded as JSON number for numeric data_types, JSON boolean for "bool", JSON string otherwise. Unparseable numerics fall back to JSON string so user content is never lost. For external roles, the value is the external name and is always a JSON string. Omitted when empty.
mode_overloads object optional Member only. Each entry maps a mode to the value that overrides the member default in that mode. Uses the same encoding as value. Omitted when empty.
stages string[] optional Per-pin stage override. Empty list means "inherit node.stage". Omitted when empty.
flip_side bool optional Renders the pin on the side opposite its role (input on the right, output on the left). Editor-only layout hint. Defaults to false; omitted when false.

External I/O

An attribute with role "external_input" or "external_output" is host-facing I/O rather than a pin. Its value is the external name the host process uses to reach it (Engine::input<T>(name) / Engine::output<T>(name)); data_type is the C++ type behind it. A node type may declare any number of them.

{ "name": "cmd",   "data_type": "float", "role": "external_input",  "value": "joint0.cmd" }
{ "name": "angle", "data_type": "float", "role": "external_output", "value": "joint0.angle" }
  • External attributes are never link endpoints (validate_connection returns KindMismatch), have no canvas pin, and ignore stages.
  • External names are optional. An unnamed external input or output is simply not exported (an unnamed input keeps its default value, like an unwired pin). The editor shows it as a lint warning.
  • External names are unique per direction across the pipeline; an input and an output may share a name.
  • External names are independent of node names and modes.

Typed value encoding

data_type JSON shape
"float", "double", "int", "uint", "int32", "int64", "uint32", "uint64", "long", "ulong", "size" number
"bool" boolean
anything else (e.g. "string", "vec3", custom) string

Numeric, boolean or mode-table values that fail to parse are emitted verbatim as a JSON string so user content always survives the round-trip. The in-memory representation is always a string -- typing only affects the JSON shape.

If a saved attribute is no longer present in the current registry's spec for node.type, an AttributeMissing diagnostic is emitted; the attribute is still loaded verbatim.

{
    "id":        7,
    "from":      { "node": 42, "attr": "torque_cmd" },
    "to":        { "node": 11, "attr": "in" },
    "data_type": "vec3"
}
Field Type Required Notes
id uint64 yes Stable handle; non-zero, unique within links.
from object yes Output endpoint. {node: NodeId, attr: string}.
to object yes Input endpoint. Same shape.
data_type string optional Snapshot of the link's data type at creation. Empty allowed but discouraged.

Diagnostics:

  • LinkOrphanedNode: either endpoint references a non-existent node.
  • LinkOrphanedAttribute: endpoint's attr is not present on the resolved node.
  • LinkTypeMismatch: data_type differs from either endpoint's current data_type, or endpoints disagree.

The link is always inserted into the graph regardless of which diagnostic fires (subject to endpoint resolution). The editor surfaces warnings; the user can re-route or delete.

Stage

{
    "name":  "control",
    "color": "#FF0000FF"
}
Field Type Required Notes
name string yes Unique within stages. References from nodes/attrs use this name.
color string optional "#RRGGBBAA". Defaults to opaque white.

Stage references in Node.stage and Attribute.stages use this name as the foreign key. If a referenced stage is not in stages[], an UnknownStageReference diagnostic fires; the verbatim string is preserved on disk and in memory.

Stages are NOT cascaded on remove -- V2 is permissive: deleted stages leave dangling references that surface as diagnostics on next load.

Profile

A profile selects a mode for each node in the pipeline. Valid selections are the node's modes and the reserved "disable" mode. A node starts with the modes declared by its type or with "enable" if its type declares none. Users can add modes to individual nodes in the Inspector.

{
    "name":     "default",
    "per_node": [
        {"node": 42, "mode": "enable"},
        {"node": 11, "mode": "disable"}
    ]
}
Field Type Required Notes
name string yes Unique within profiles.
per_node array optional Each entry is {node: NodeId, mode: string}. A node without an entry has an empty mode; piper::check_profile_modes() reports it as MissingMode.

The default profile is named at the top level ("default_profile": "..."), not inside the profile entry. A file without profiles loads with a single default profile giving every node its first mode.

per_node is keyed by NodeId, NOT by Node::name. Renaming a node does not break profile entries.

The loader preserves mode names as written. piper::check_profile_modes() reports a selection outside the node's available modes as UnknownMode. The editor dims nodes in "disable" and uses Theme::mode_colors or a pastel hue derived from the mode name for other modes.

If a per_node entry references a node not in the graph, an OrphanProfileReference diagnostic fires; the entry is preserved.

Diagnostic kinds

The deserializer returns a LoadResult { Graph, vector<Diagnostic> }. Diagnostic kinds:

Kind Triggered by
SchemaError Malformed entry (missing required field, bad role string, malformed pos, malformed color, etc.). The offending entry or field is skipped; a default may apply.
DuplicateNodeId Same node ID appears twice in nodes[].
DuplicateLinkId Same link ID appears twice in links[].
DuplicateStageName Same stage name appears twice in stages[].
DuplicateProfileName Same profile name appears twice in profiles[].
DuplicateTypeName Same node-type name appears twice in types[] (registry format).
UnknownNodeType node.type not in the registry passed to deserialize.
AttributeMissing Saved attribute name not present in the current registry spec.
AttributeAdded Registry spec has an attribute not present in the saved node (engine should apply the default).
AttributeDrift Saved attribute.data_type or attribute.role differs from the current spec's.
LinkOrphanedNode Link endpoint references a non-existent node. Link is dropped.
LinkOrphanedAttribute Link endpoint references an attribute not on the node. Link is dropped.
LinkTypeMismatch Link's data_type differs from endpoint data_types, or endpoints disagree. Link is still inserted -- engine consumers must check diagnostics before trusting any link.
OrphanProfileReference Profile per_node entry references a non-existent node. Entry is preserved verbatim.
UnknownStageReference Node.stage or Attribute.stages references a stage not in stages[]. Reference preserved verbatim.
DefaultProfileRepaired default_profile names a profile not in profiles[]; the first profile becomes the default.
UnknownMode piper::check_profile_modes() reports a profile entry whose mode is outside the node's available modes.
MissingMode Not emitted by the loader: piper::check_profile_modes() reports a node without an entry in a profile.

Each diagnostic carries a human-readable message plus optional locator fields (node_id, attr_name, link_id) that the editor uses to focus the offending element on click.

Registry catalog format

A separate JSON shape -- produced by v2::serialize_registry, consumed by v2::deserialize_registry. Engines ship their own catalog file; Piper loads it at startup to know the available node types. This is independent of any specific graph file.

{
    "version": 3,
    "types": [
        {
            "type": "PID",
            "library": "control",
            "category": "control",
            "help": "Proportional-integral-derivative controller",
            "attributes": [
                {"name": "setpoint", "data_type": "float", "role": "input"},
                {"name": "measured", "data_type": "float", "role": "input"},
                {"name": "out",      "data_type": "float", "role": "output"},
                {"name": "kp",       "data_type": "float", "role": "member", "default_value": "1.0"}
            ],
            "modes": ["tight", "loose"]
        }
    ]
}
Top-level field Type Required Notes
version int yes 3 (2 is also accepted). Any other value causes the loader to throw.
types array optional Defaults to []. Type entries are sorted by name on emit for deterministic diffs.

Each type entry:

Field Type Required Notes
type string yes Unique within types. Duplicate names -> DuplicateTypeName diagnostic; first entry wins.
library string optional Free-form tag for grouping in palettes (e.g. "math", "control").
category string optional /-delimited path grouping the type in the "Add node" menu (e.g. "filter", or "hal/motor" for a nested submenu). Empty -> the type sits at the menu root.
help string optional One-line description.
attributes array optional Each entry is an AttributeSpec: name, data_type, role (required) plus optional default_value and optional (bool, default false: input-role only, the pin may stay unwired). Same shape as graph-file attributes minus value and stages.
modes array optional Modes the step handles itself, copied into each new node. "disable" is implicit; none means a new node starts with "enable".

Diagnostics emitted by deserialize_registry:

  • SchemaError -- missing required field, malformed entry. The bad entry is skipped.
  • DuplicateTypeName -- same type name appears twice. First wins.

Unlike graph files, registry files don't reference each other -- they're flat declarative descriptors.

Example

A single-pipeline motor-control snippet:

{
    "version": 3,
    "pipelines": [
        {
            "name": "main",
            "meta": {
                "author":      "phil",
                "description": "torque feedback prototype"
            },
            "default_profile": "default",
            "nodes": [
                {
                    "id": 1, "type": "Bus", "name": "main_bus", "stage": "control",
                    "pos": [100, 100],
                    "attrs": [
                        {"name": "torque_cmd",  "data_type": "vec3",  "role": "output", "stages": ["control"]},
                        {"name": "torque_meas", "data_type": "vec3",  "role": "input",  "stages": ["feedback"]},
                        {"name": "gain",        "data_type": "float", "role": "member", "value": 0.5}
                    ]
                },
                {
                    "id": 2, "type": "LowPass", "name": "lowpass", "stage": "feedback",
                    "pos": [250, 100],
                    "attrs": [
                        {"name": "in",     "data_type": "vec3",  "role": "input"},
                        {"name": "out",    "data_type": "vec3",  "role": "output"},
                        {"name": "cutoff", "data_type": "float", "role": "member", "value": 10.0}
                    ]
                }
            ],
            "links": [
                {"id": 1, "from": {"node": 1, "attr": "torque_cmd"}, "to": {"node": 2, "attr": "in"},          "data_type": "vec3"},
                {"id": 2, "from": {"node": 2, "attr": "out"},        "to": {"node": 1, "attr": "torque_meas"}, "data_type": "vec3"}
            ],
            "stages": [
                {"name": "control",  "color": "#FF0000FF"},
                {"name": "feedback", "color": "#00FF00FF"}
            ],
            "profiles": [
                {
                    "name": "default",
                    "per_node": [
                        {"node": 1, "mode": "enable"},
                        {"node": 2, "mode": "enable"}
                    ]
                }
            ]
        }
    ]
}