Exporting & Format Detection
toJSON
Currently one export format is available: generic JSON.
typescript
import { toJSON } from 'mcmc-visualizer';
const jsonString = toJSON(data);
// Output: { "chain#1": { "mu": [1.2, 1.3, ...], "sigma": [...] }, "chain#2": { ... } }This format is readable by fromChainArrays() after JSON.parse().
detectFormat
typescript
import { detectFormat } from 'mcmc-visualizer';
const format = detectFormat(text);
// 'turing-csv' | 'stan-csv' | 'mcmcchains-json' | 'unknown'Detection priority:
- Starts with
{and hassize,value_flat,parameters→mcmcchains-json - First non-comment line has
lp__andaccept_stat__headers →stan-csv - Header has
iteration,chainorchain_,draw_→turing-csv(wide) - 4-column CSV where columns 3+4 are numeric integers/floats →
turing-csv(long) - Otherwise →
unknown
ArviZ JSON is not auto-detected (it requires fromArviZJSON() explicitly) because it has an ambiguous { prefix.