unstringify

v0.1.1
io.github.tekinnnnn/unstringify Checked 5 hours ago Published 2 months ago

Fix broken JSON by line, validate, convert, read CSV/NDJSON/logs as records, unpack, compare.

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

fix_json Fix JSON

Fix broken JSON (or YAML, XML) with named, line-by-line fixes: single quotes, unquoted keys, trailing commas, Python True/False/None, missing commas, a truncated file, a code fence around it. Returns the fixed text, each fix by line and kind, and whether the result is valid now. Deterministic — no guessing at content.

ParameterTypeDescription
formatstringAbsent: detected.
pathstringA file to read instead of `text`, relative to the working directory.
textstringThe text to work on. Either this or `path`.

validate Validate

Say whether text is valid JSON, YAML or XML, and where it is not: line, column, the parser’s message, and a hint when the engine has one. Detects the format when not told.

ParameterTypeDescription
formatstringAbsent: detected.
pathstringA file to read instead of `text`, relative to the working directory.
textstringThe text to work on. Either this or `path`.

convert Convert

Convert between JSON, YAML, XML, CSV, NDJSON, a Markdown table and TypeScript interfaces. A document into rows takes its main list of records, the rest of the document repeated on every row (the way pandas normalizes); rows into JSON is one array. Targets: yaml, csv, ts, markdown, ndjson, xml, json, json-min.

ParameterTypeDescription
to *stringThe target format.
delimiterstringCSV/TSV separator. Absent: detected.
fromstringThe source format. Absent: detected.
headerbooleanCSV/TSV: is the first row the header? Absent: decided from the rows.
pathstringA file to read instead of `text`, relative to the working directory.
patternstringLog: a regex with named groups to read each line with. Absent: the best of the known shapes, measured.
rootNamestringTypeScript: the root interface name. Default Root.
textstringThe text to work on. Either this or `path`.

read_records Read as records

Read CSV, TSV, NDJSON, a Markdown table or a raw log as records — one JSON value per row, the header as keys, a log line split by the best known shape (JSON lines, logfmt, nginx, syslog…) or your regex with named groups. Returns the records, the counts (rows, broken, raw lines kept), the columns and the level counts.

ParameterTypeDescription
delimiterstringCSV/TSV separator. Absent: detected.
formatstringAbsent: detected.
headerbooleanCSV/TSV: is the first row the header? Absent: decided from the rows.
pathstringA file to read instead of `text`, relative to the working directory.
patternstringLog: a regex with named groups to read each line with. Absent: the best of the known shapes, measured.
textstringThe text to work on. Either this or `path`.

unpack Unpack

Open every string value that holds JSON, XML or YAML — an SNS envelope’s Message, a Kibana row’s message column, a double-encoded field — in place: the literal is replaced by what it held and every other byte stays where it was. NDJSON is unpacked one line at a time. Pass `path` (a JSON path such as $.Message) to open one value only.

ParameterTypeDescription
formatstringAbsent: detected.
pathstringA file to read instead of `text`, relative to the working directory.
textstringThe text to work on. Either this or `path`.
valuePathstringOpen only the value at this path, e.g. $.Message.

compare Compare

Compare two documents by structure — keys sorted, whitespace ignored, one row per path that differs — or two sets of rows (CSV, NDJSON, a log) by key: which records were added, removed, changed, and in which fields. Formatting differences are not differences.

ParameterTypeDescription
delimiterstringCSV/TSV separator. Absent: detected.
formatstringBoth sides’ format. Absent: detected from the left.
headerbooleanCSV/TSV: is the first row the header? Absent: decided from the rows.
keystring | nullRows: the field to match records on. Absent: detected; null: line order.
leftstringThe left text. Either this or `leftPath`.
leftPathstringA file to read for the left side.
patternstringLog: a regex with named groups to read each line with. Absent: the best of the known shapes, measured.
rightstringThe right text. Either this or `rightPath`.
rightPathstringA file to read for the right side.