The .coppa file format

The open, documented JSON format of a .coppa file, for reading and writing circuits from any language.

This page is the file format specification kept with Coppa’s source as docs/FILE-FORMAT.md, published here as it stands.

A .coppa file is one UTF-8 JSON document. It holds every circuit page with its parts, wires and probes, plus the run setup, graphs, window layout and the document's extras. The format is open: you can read and write it from any language, diff it in git and generate it from scripts.

  • JSON Schema: docs/coppa.schema.json in Coppa’s source (draft 2020-12). CoppaTests/Documents/FileSchemaTests.swift checks every bundled example, every lesson and a file with every section filled in against it, so the schema can't drift from what Coppa writes.
  • Source of truth: Coppa/Documents/CoppaFile.swift and the Codable types it uses (listed under each section below).
  • Uniform Type Identifier: app.coppa.circuit (conforms to public.json), extension .coppa.

Versions#

KeyNowMeaning
version1The data layout. Bumped only when a change means an older Coppa can't read the file.
formatVersion2How the text is laid out. 1 was plain JSONEncoder output; 2 is the canonical layout below. Coppa reads both the same way. Written for other tools; Coppa never needs it.

New features add keys rather than change old ones, so version has stayed at 1. A file from a newer Coppa opens in an older one: unknown keys are skipped and the rest loads.

Reading rules (tolerant decoding)#

Coppa never refuses a file because one piece is odd. A reader should do the same:

  1. Missing key: use the default listed below. Almost every key is optional; the only required keys are a part's name, a drawing's kind, a block pin's name, a block reference's definition, a canvas graph's trace and a layout window's tab.
  2. Unreadable value (wrong type, unknown enum case): use the default for that key, not an error.
  3. Arrays are lossy: an element that can't be read is dropped and the others are kept, so one part from a newer Coppa doesn't lose the page.
  4. Unknown keys: ignore them.
  5. Unknown enums inside parts read as their safe value (an unknown fault reads as none, an unknown damage as open).

The schema sets additionalProperties: false so that it documents every key Coppa writes. Don't use that strictness to reject files in a reader.

Writing rules (canonical output)#

Coppa writes the same bytes for the same circuit, so files diff well (Coppa/Documents/CanonicalJSON.swift):

  • Keys sorted alphabetically at every level.
  • An object or array that fits in 100 characters stays on one line (a point, a wire, a probe); anything longer is spread out one entry per line, indented by two spaces.
  • Numbers with floating-point noise (0.30000000000000004) are written to 15 significant digits. Whole numbers have no decimal point.
  • Slashes aren't escaped. The file ends with a newline.
  • Parts, wires and probes keep the order they were placed in. Adding a part adds lines at the end of its page, and moving or renumbering one changes only its lines.
  • Settings left at their default are often left out (marked "omitted when default" below). Readers fill the same defaults back in.

Value types#

TypeJSONExample
point[x, y] in schematic grid units (one grid square = 1)[12, 4]
size[width, height][16, 8]
range[lower, upper][0, 0.001]
UUIDupper-case string with hyphens"6F1C…-…"
datenumber of seconds since 2001-01-01 00:00:00 UTC800000000
dataBase64 string"iVBORw0K…"
value texta part value as typed, always with a full stop for decimals"4.7k", "10u tol=5%"

Part values, run times and SPICE text stay in POSIX number format whatever the Mac's region.

Top level (CoppaFile)#

KeyTypeDefaultNotes
versioninteger1See Versions.
formatVersioninteger—See Versions.
pagesarray of page[]Circuit pages in tab order.
selectedPageinteger0Index of the page in front when saved.
analysisanalysis settingsdefaultsWhat ▶ runs.
generatorfunction generatordefaultsThe bench function generator.
runSetupsarray of run setup[]Saved run configurations.
activeRunSetupinteger0Index into runSetups.
snapbooleantrueSnap to grid.
showGridbooleanfalse
blocksarray of block definition[]Subcircuits used in the file, so it opens anywhere.
plotsobject: page index ("0", "1" …) → plot settings{}Each page's graph.
layoutlayoutabsentHow the window was laid out. Not part of the circuit.
extrasextrasempty, omittedPart numbers, attachments, comments, requirements, output jobs.
lablababsent, omitted when emptyA lesson's or teacher's lab sheet.
studiostudioempty, omittedLock, title block, variants, rules-check settings.
symbolsarray of drawn symbol[], omitted when emptySymbols drawn in the Symbol Editor or imported from KiCad, EAGLE or Altium, used in the file.

Page (CoppaFile.Page)#

name (string, default "Untitled") and schematic.

Schematic (Schematic, Coppa/Models/Schematic.swift)#

KeyTypeDefault
partsarray of part[]
wiresarray of wire[]
probesarray of probe[]
temperaturenumber, °C27
signalinput signaldefaults
busesarray of busomitted when empty
notesarray of noteomitted when empty
drawingsarray of drawingomitted when empty

Wires connect wherever a wire end or corner meets a pin or another wire; there is no separate net list. Coppa works out nets from the geometry.

Part (PlacedPart)#

KeyTypeDefaultNotes
idUUIDnew
namestringrequiredCatalogue name ("Resistor", "TL072") or an imported model's name.
referencestring""R1, U1 …
valuevalue text""May carry extras such as tol=5%, tol=+80%/-20%, drift=1%.
positionpoint[0, 0]
rotationinteger0Quarter turns clockwise; omitted when 0.
mirroredbooleanfalseOmitted when false.
referenceOffset, valueOffsetpoint[0, 0]Labels dragged from their usual place; omitted when zero.
closedbooleanfalseA switch that's closed.
wipernumber 0–10.5A potentiometer's wiper; omitted when 0.5.
wiperKeystring"A"The key that turns the wiper.
blockblock referenceabsentThe part is a subcircuit.
digitaldigital settingsabsentLogic parts (gate inputs, widths, memory).
devicedevice settingsabsentMicrocontroller boards and modules.
spiceModelstringabsentAn imported SPICE model, embedded so the file opens on another Mac.
referenceLockedbooleanfalseRenumbering leaves it alone.
hidesReference, hidesValuebooleanfalseLabel hidden on the schematic.
powerRatingnumber, WabsentFor over-power warnings.
voltageRatingnumber, VabsentFor over-voltage warnings.
optionspart optionsomitted when default

Part options (PartOptions): disabled (left out of the netlist), fault (none, open, short, drift), drift (fraction, 0.2 = +20 %), ideal (ideal or real model), stimulus (a sensor's input or a motor's load), position (a rotary switch's position), blown (a fuse), damage (open or short, what overload did), charge (a battery's starting charge, 0–1). Each is omitted when default.

Digital settings (DigitalSettings, Coppa/Digital/GenericLogic.swift): inputs (gate inputs), inverted (bit mask of inverted inputs), bits (width), dataBits (memory data width), memory (RAM/ROM contents), switches (bit mask of DIP switches on), logicView (drawn as a logic symbol), code (a Verilog block's module or a script's Python), inputPorts and outputPorts (a script block's or script source's ports, such as A, B, D[3:0]), analogue (a script block that reads and drives volts), splitBuses (vector ports as one pin per bit), stateMachine (a state machine part's machine) and gateBlock (the id of the block of gates built from it).

A state machine (StateMachine, Coppa/Digital/StateMachine/StateMachine.swift) has inputs and outputs (signal names), states (each id, name, x, y in the editor, and outputs, the Moore outputs that are 1), transitions (each id, from, to, condition, a Verilog expression of the inputs that is empty for always, and outputs, the Mealy outputs that are 1), initial (a state id; absent for the first), style (moore or mealy) and encoding (binary, oneHot or gray). All of its keys are written.

Device settings (DeviceSettings, Coppa/Microcontrollers/DeviceSettings.swift): language (sketch, python, flowchart, firmware), source (program text), firmware (data, e.g. an Intel HEX image), firmwareName, flowchart, breakpoints (line numbers), watches (variable names), serialInput, readings (a module's settable readings by name), pressed (keys held), address (an I²C address), count (e.g. LEDs on a strip), boardView.

A flowchart (Flowchart) has setup and loop, each an array of blocks. A block (FlowBlock) has id, kind (pinMode, digitalWrite, analogWrite, digitalRead, analogRead, delay, print, set, decision, repeatTimes, wait), pin, value, variable, comparison, text, and the nested body and otherwise arrays. All block keys are written and read.

Wire, bus, probe, note, drawing#

  • Wire (Wire): id, points (corners), optional colour (blue, purple, pink, red, orange, yellow, green, mint, teal, cyan, indigo, brown, graphite).
  • Bus (Bus): id, points, label (its members, e.g. D[0..7] or A[7:0]), and radix (hex, decimal or binary, how its value is shown while simulating; omitted for hex).
  • Probe (Probe): id, kind (voltage, current, power, differential, digital, reference), number, at (point), and optional colour (red, green, blue, each 0–1), label, tagOffset (point), partID (the part a current or power probe measures).
  • Note (Note): id, at (top-left), text, kind (text or table; a table's cells are tab- and line-separated in text).
  • Drawing (Drawing, Coppa/Annotation/Drawing.swift): id, kind (line, arrow, rectangle, ellipse, arc, bezier, image), points, and for an image, image (data: PNG, JPEG or PDF bytes).

Input signal (InputSignal)#

The page's signal source: amplitude (V), frequency (Hz), shape (Sine, Square, Triangle, Sawtooth, Custom), offset (V), duty (0–1), edge (fraction of a period), custom (one period of samples for Custom).

Run setup#

Analysis settings (AnalysisSettings, Coppa/Simulation/AnalysisSettings.swift):

KeyTypeNotes
kindstringtran, ac, op or dc. Older files hold the display name ("Transient"), which still reads.
stopTimevalue textTransient length, e.g. "20m".
maxStepvalue textEmpty means automatic.
acStart, acStopvalue textAC sweep range in Hz.
accuracystringFast, Balanced or Precise.
whenStuckstringWhat to do when the solver can't converge: Explain the cause and suggest a fix, Retry automatically with safer settings, Stop and show the raw SPICE message.
startFromZerobooleanSkip the operating point.
adaptiveStepboolean
startupKickbooleanOmitted when true.
designScriptstringOmitted when empty.
automaticWindowbooleanPick the run length from the circuit.
dcSource, dcStart, dcStop, dcStepstringDC sweep; each omitted when empty.

Run setup (CoppaFile.RunSetup): name, detail, optional analysis (a kind code).

Function generator (FunctionGeneratorSettings): waveform (Sine, Square, Triangle, Ramp, Pulse), frequency (Hz), amplitude (V), offset (V), phaseDegrees, dutyCycle (%), highZLoad.

Subcircuits (Coppa/Hierarchy)#

  • Block definition (BlockDefinition): id, name, schematic (its inside), symbol (a block symbol, or null for an automatic one), isSheet (a hierarchical sheet rather than a reusable block).
  • Block reference (BlockRef, on a part): definition (the definition's id, required), symbol, revision.
  • Block symbol (BlockSymbol): pins and optional width (grid squares; absent fits the pin names).
  • Block pin (BlockPin): name (required, matches a port inside), side (left, right, top, bottom).
  • A block symbol may also carry drawn, a drawn symbol worn instead of the plain box (a custom look).
  • Drawn symbol (DrawnSymbol, Coppa/Models/Symbols/DrawnSymbol.swift): id, name, reference (prefix such as U), shapes (drawings: line, rectangle, ellipse, arc through its third point, bezier), texts, pins, optional source (where it was imported from), model (a SPICE model name) and notes. Grid units, y down, around the part's origin.
  • Symbol text (SymbolText): id, text, at, size (grid units).
  • Symbol pin (SymbolPinDef): id, name, number, direction (passive, input, output, bidirectional, power, openCollector, unconnected), at (where wires meet it, a whole grid point), side (the body side it leaves from), length (grid units), and modelPin (the block Port or SPICE pin it stands for; omitted when it's the pin's name).

Graphs (plots, PlotSettings, Coppa/Views/Graph/GraphTools.swift)#

KeyTypeNotes
layoutstring"scope" or another graph layout.
hiddenarray of UUIDProbes not shown.
expressionsarray of stringAdded traces, e.g. "V(out)/V(in)".
measurementsarray of measurement
limitsobject: trace → limit line
notesarray of graph note
linkedXbooleanStacked charts share one time axis.
axisLocksobject: chart → axis lockCharts: "time", a stacked pane's first trace, "gain", "phase", "dc".
scopeMeasuresarray of stringpeakToPeak, rms, mean, maximum, minimum, amplitude, frequency, period, duty, rise, fall.
namesobject: trace key → nameFriendly trace names.
canvasGraphsarray of canvas graphLive graphs on the schematic.
  • Measurement (MeasureDefinition, Coppa/Simulation/Measurements.swift, like SPICE .meas): id, name, function (Average, RMS, Minimum, Maximum, Peak to Peak, Integral, Slope At, Value At, Value When, When, Delay, Rise Time, Fall Time), expression, optional window from and to (s), optional at (s), three crossings when, trigger and target, and lowFraction and highFraction for rise and fall times. All but the optional keys are required.
  • Crossing (Crossing): expression, level, edge (Rising, Falling, Either), occurrence (1 = first, 0 = last).
  • Limit line (LimitLine): optional lower and upper.
  • Graph note (GraphNote): id, time, value, text, trace, all required.
  • Axis lock (AxisLock): optional x and y ranges.
  • Canvas graph (CanvasGraph): id, trace (a probe's UUID, required), at (point), size.

Window layout (layout, LayoutState, Coppa/Documents/LayoutState.swift)#

Only how the window looked; a reader that doesn't show windows can ignore it.

KeyTypeNotes
panesarray of paneEditors in the window.
focusedintegerIndex of the focused pane.
split[x, y]Divider positions, 0–1.
sidebarboolean
navigatorstringThe sidebar tab ("parts" …).
inspectorsarray of editor kindKinds of editor that show the inspector.
resultsbooleanResults area shown.
resultsHeightnumberPoints.
resultsTabstringwaveforms, measurements or log.
windowsarray of windowTabs open in windows of their own.
  • Editor kind: circuit, graph, instrument, grapher.
  • Tab: kind, page (index into pages; -1 for the Grapher), optional instrument (its stable name, e.g. "oscilloscope").
  • Pane: tabs, selected, tile ([column, row, columns, rows] on a 2 × 2 grid), views.
  • View: tab (index into the pane's tabs), pan ([x, y]), zoom.
  • Window: tab (required) and optional frame ([x, y, width, height] in screen points).

Extras (extras, DocumentExtrasRecord, Coppa/Documents/DocumentExtras.swift)#

Each key is omitted when empty.

  • sourcing: object of part id → part sourcing, for the bill of materials. Part sourcing (PartSourcing): mpn, manufacturer, lcsc, footprint.
  • attachments: files kept inside the circuit (datasheets, photos). Attachment (Attachment): id, name (file name), typeIdentifier (a UTI such as com.adobe.pdf), data (the file's bytes, Base64), optional partID (the part it belongs to), added (date). One attachment is at most 20 MB and all of them together at most 50 MB.
  • comments: review comments. Comment (ReviewComment): id, page (page index), at (point), text, author, date, resolved.
  • requirements: pass/fail specs checked after a run. Requirement (Requirement): id, text, measurement (a measurement's name), optional minimum and maximum, page.
  • outputJobs: one-click exports. Output jobs (OutputJobs): outputs (pdf, png, svg, bom, jlcpcb, netlist, circuitikz), optional folderBookmark (a macOS security-scoped bookmark, data) and folderPath.

Lab (lab, LabRecord, Coppa/Learning/LabRecord.swift)#

A lesson or a teacher's lab sheet: title, instructions, optional lessonID (a built-in lesson), questions, lockedValues (part id → value the student can't change), hiddenInstruments (instrument stable names), isStudentCopy.

Question (LabQuestion): id, prompt, expected (number), tolerance (fraction, default 0.05), unit, answer (the student's answer as typed).

Studio (studio, StudioRecord, Coppa/Annotation/StudioState.swift)#

Each key is omitted when default.

  • locked: the circuit is locked against edits (switches still flip).
  • titleBlock: Title block (TitleBlockInfo): title, author, company, revision, optional date, showsOnCanvas.
  • variants: build variants. Variant (PartVariant, Coppa/Annotation/Variants.swift): id, name, notFitted (part ids left off the board), values (part id → value for this variant).
  • activeVariant: the variant in use (UUID).
  • disabledRules: rules-check rules turned off, by rule id.
  • ignoredIssues: rules-check findings marked as ignored, by issue key.

Example#

A 1 kΩ / 1 µF RC low-pass on a 5 V step, as Coppa writes it (ids shortened here; real files hold full UUIDs):

{
  "activeRunSetup": 0,
  "analysis": {
    "acStart": "10", "acStop": "100k", "accuracy": "Balanced", "adaptiveStep": true, "automaticWindow": true,
    "kind": "tran", "maxStep": "", "startFromZero": false, "stopTime": "10m",
    "whenStuck": "Explain the cause and suggest a fix"
  },
  "blocks": [],
  "formatVersion": 2,
  "generator": {
    "amplitude": 1, "dutyCycle": 50, "frequency": 1000, "highZLoad": true, "offset": 0, "phaseDegrees": 0,
    "waveform": "Sine"
  },
  "pages": [
    {
      "name": "RC filter",
      "schematic": {
        "parts": [
          {"id": "A1…", "name": "DC supply", "position": [4, 8], "reference": "V1", "value": "5"},
          {"id": "B2…", "name": "Resistor", "position": [10, 4], "reference": "R1", "value": "1k"},
          {"id": "C3…", "name": "Capacitor", "position": [16, 8], "reference": "C1", "rotation": 1, "value": "1u"},
          {"id": "D4…", "name": "Ground", "position": [10, 14], "reference": "", "value": ""}
        ],
        "probes": [{"at": [16, 4], "id": "E5…", "kind": "voltage", "label": "Vout", "number": 1}],
        "signal": {"amplitude": 0.01, "custom": [], "duty": 0.5, "edge": 0.005, "frequency": 1000, "offset": 0, "shape": "Sine"},
        "temperature": 27,
        "wires": [
          {"id": "F6…", "points": [[4, 4], [8, 4]]},
          {"id": "G7…", "points": [[12, 4], [16, 4], [16, 6]]}
        ]
      }
    }
  ],
  "plots": {},
  "runSetups": [],
  "selectedPage": 0,
  "showGrid": false,
  "snap": true,
  "version": 1
}

The smallest file Coppa opens is {"pages": [{"name": "Empty", "schematic": {}}]}; every other key takes its default.

Changing the format#

  • Add keys; don't rename or repurpose them. Give every new key a default and decode it with c.value(_:default:), c.optional(_:) or c.lossyArray(_:) so older files still open.
  • Leave a new key out when it holds its default, so existing files don't change when they're saved again.
  • Add the key to docs/coppa.schema.json and to this document. FileSchemaTests fails until both know about it.
  • Bump CoppaFile.currentVersion only for a change an older Coppa can't read, and say here what changed.

Applies to Coppa 0.1 Preview 14. Last updated 22 November 2026.