# TSV to JSON string records v1

Save `tsv-json.mjs` beside `tsv-json-example.mjs` containing this example.
Run `node tsv-json-example.mjs` with Node 18+; no runtime dependencies or network.

```js
import assert from 'node:assert/strict';
import { tsvToJson } from './tsv-json.mjs';
const result = tsvToJson('id\tactive\tnote\n001\tfalse\t\n002\t0\t=1+1');
assert.deepEqual(JSON.parse(result.json), [
  { id: '001', active: 'false', note: '' },
  { id: '002', active: '0', note: '=1+1' },
]);
assert.equal(result.rows, 2);
console.log('TSV to JSON example passed.');
```

## Contract

`tsvToJson(input)` returns `{ json, report, rows, columns }`. JSON is an array
of objects, formatted with two-space indentation. The first row supplies exact
field names. Empty or whitespace-only names and duplicate literal names reject;
other header spaces remain. Every value is a string, including empty cells,
leading zeros, numeric text, false and formulas. Nothing evaluates or changes
a spreadsheet. Special keys such as `__proto__`, `constructor` and `toString`
remain own JSON properties. Integer-like keys may display in numeric order;
JSON objects are not an ordered-column format.

Paste literal tab-separated cells. Quotes do not escape tabs or line endings;
this is not a CSV parser. CRLF and CR normalize to LF; one terminal newline is
ignored. All data rows must match the header width. Header-only input yields
`[]`. Values never become numbers, booleans or null; whitespace is not trimmed.

Limits: 100,000 input characters, 500 rows including the header, 50 columns,
300,000 output JSON characters. Repeated long field names and JSON escaping
can reach the output bound even for small input. Errors stop the preview.
No file writes, requests, formulas or safe-import guarantee. Validate the
receiving application's schema separately. Native export plus a local script
is an alternative; no measured advantage or user demand is claimed.

## Source parity

Generated from the browser's exact `site/lib/tsv-json.ts` core with
`node scripts/build-tsv-json.mjs`; use `--check` to verify bytes. Tests compare
runtime results/errors and execute this example. A download is not evidence
of independent local execution. Input and output are not sent in analytics.

## License

MIT License

Copyright (c) 2026 QuasiLife

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
