Skip to content

Save and load API

Use JSON to preserve raw data and images to preserve appearance. See the save and load guide for working examples.

On this page

saveMeasurement(record)

Import from nmrlink/browser. Downloads the supplied record as readable JSON with indentation and a trailing newline. Returns no value and leaves the record unchanged. Call it from a user click.

The filename is nmrlink-acquisition-time_JST.json using Japan time. acquiredAt inside the record is unchanged. It saves the entire supplied record without cropping samples to the graph limits.

parseMeasurement(text) and readMeasurement(file)

parseMeasurement is synchronous, from nmrlink; readMeasurement is asynchronous, from nmrlink/browser. They accept a string / File and return a validated measurement record, without communicating with hardware.

ValidationRequirement
SizeAt most 2 MiB in UTF-8
source / modeinstrument or demo / single or double
points / sampleIntervalMs2048 / 0.02
raw2048 finite numeric pairs; numeric strings are refused
acquiredAt / parametersValid acquisition date / settings; only demo allows parameters:null

Unknown fields and stored analysis results are discarded. parseMeasurement throws; readMeasurement rejects for reading or validation errors. Replace the current record and view only after reading and analysis succeed.

js
const file = fileInput.files[0];
if (file) {
  try {
    const record = await readMeasurement(file);
    const analysis = analyzeMeasurement(record);
    graphs.show(record, analysis);
  } catch (error) {
    status.textContent = error.message;
  }
}

saveGraphPng(svg, options)

Import from nmrlink/browser. Returns a promise that converts an SVG element to an opaque white-background PNG and downloads it. Defaults: filename=nmrlink-graph.png, scale=2. Scale must be greater than zero and at most four; output dimensions are limited to 8192 px per side and 16 megapixels total.

Preserves visible axes, labels, traces, colors and analysis regions without modifying the source SVG or record. Invalid SVG/scale arguments and conversion failures throw or reject. Pass SVG generated by NMRLink from your own UI.

formatFileTimestamp(acquiredAt)

Import from nmrlink/browser. Converts a date string to a Japan-time filename component, independent of the computer timezone. Invalid dates throw TypeError.

js
const name = formatFileTimestamp("2026-10-21T06:00:00.000Z");
// "2026-10-21_15-00-00-000_JST"

Restore a full scan archive

Import from nmrlink. These synchronous parsers accept JSON strings saved by the corresponding Web UI. They recompute amplitudes and fits from raw records rather than trusting stored derived values.

FunctionMain result fields
parseFrequencySweep(text)source, acquiredAt, settings, points
parsePulseCalibration(text)The above plus calibration, referenceIndex, phaseDegrees
parseT1Measurement(text)Basic four fields plus result, referenceIndex, phaseDegrees, fromMs, toMs
parseT2Measurement(text)Basic four fields plus result, referenceIndex, fromMs, toMs

Limits: 32 MiB and 1–201 points. Partially completed scans are supported. Inconsistent settings, points, references or fit ranges throw. Valid zero-signal pulse/T1/T2 archives can still be opened for waveform inspection, with calibration or result set to null.

MAX_FREQUENCY_JSON_BYTES, MAX_PULSE_JSON_BYTES, MAX_T1_JSON_BYTES and MAX_T2_JSON_BYTES each equal 32 × 1024 × 1024. There is no dedicated scan-save API; the Web UI assembles the corresponding JSON formats.

API index