The reading room
Files and data guides.
Practical ways to inspect, validate, transform, and compare text, JSON, CSV, and binary data.
30 guides · Examples, explanations, and practical limits.
In this topic
30 articles
Catch malformed JSON before using imported data
Wrap JSON.parse in a controlled error boundary when reading external text. Separate syntax failure from later schema validation so a valid JSON value is not…
Validate required fields in a JSON record
After parsing JSON, validate the fields your application actually needs. Check the container type, required properties, and permitted value ranges before starting a…
Distinguish JSON arrays, objects, and null
Use Array.isArray to recognize a JSON array and a separate null check for an object record. Typeof alone reports object for both arrays and null.
Understand missing values during JSON serialization
JSON.stringify treats undefined differently in object properties and array slots. Object properties can disappear, while array positions become null so the array’s…
Restore known date fields after parsing JSON
Dates normally serialize as ISO strings in JSON. Restore a Date only for fields whose schema defines a timestamp, and validate the resulting date before using it.
Handle a leading UTF-8 BOM in text imports
If your importer permits a leading byte-order mark, remove only the first decoded U+FEFF before JSON.parse. Do not strip that character indiscriminately from the…
Pretty-print JSON without changing its data
Parse a JSON document and stringify it with an indentation argument to improve readability. Keep the original when formatting data whose exact byte representation or…
Serialize a flat object with sorted keys
For a flat object with ordinary textual keys, sort the keys before creating a serialized view. This can make small configuration diffs easier to read without changing…
Parse newline-delimited JSON records
For small newline-delimited JSON input, parse each nonempty record line separately and attach the line number to errors. Each line is an independent JSON value,…
Keep incomplete records between stream chunks
Treat stream chunks as arbitrary pieces of data, not complete records. Keep an unfinished tail between chunks and process only records whose delimiter has actually…
Escape fields when writing CSV
Quote a CSV field when it contains a comma, quote, or line break, and double embedded quotes inside quoted fields. Joining raw values with commas cannot represent…
Parse a small quoted CSV record
A CSV parser needs to distinguish commas inside quotes from actual field separators. A small state machine can demonstrate the rule, while a maintained parser is…
Choose an explicit policy for TSV fields
For a simple tab-separated export, decide what happens when a field contains a tab or line break. Rejecting unsupported content is clearer than silently producing a…
Treat CSV formula interpretation as a separate issue
CSV quoting does not stop spreadsheet applications from interpreting a cell as a formula. When exporting untrusted text for spreadsheets, choose a consumer-specific…
Preserve leading zeros in identifiers
Keep identifiers as strings when leading zeros are meaningful. A code such as 00123 is not necessarily a quantity, and converting it to a number discards information.
Reject invalid UTF-8 instead of replacing bytes
Use TextDecoder with fatal true when invalid UTF-8 should stop an import. The default replacement behavior can hide encoding problems by substituting replacement…
Keep binary files as bytes until decoding is justified
Read binary content as bytes rather than assuming every selected file is text. Text decoding is a separate interpretation step and can replace byte sequences that are…
Base64-encode a small byte array in a browser
Btoa encodes a binary string, not arbitrary Unicode text. For a small byte array, map each byte to a code unit before encoding; encode text to UTF-8 bytes first if…
Read a binary integer with an explicit byte order
Use DataView when a binary format specifies integer widths and byte order. Pass the endianness flag deliberately instead of assuming the host machine’s native layout…
Convert a byte array to a hexadecimal string
Convert each byte to base 16 and pad it to two characters to obtain a readable hexadecimal representation. Padding preserves byte boundaries for small values.
Compare two lists of identifiers
Use sets to compute identifiers present in one list but absent from another. Label the direction explicitly, because A minus B answers a different question from B…
Compare lists while preserving duplicate counts
Count occurrences with a Map when repeated entries are meaningful. A set comparison cannot distinguish one copy of an ID from several copies of the same ID.
Count text lines with an explicit trailing-newline rule
Define whether a final newline terminates the last record or creates an additional empty record. For a common text-line convention, an empty file has zero lines and a…
Normalize text line endings deliberately
Replace CRLF and standalone CR with LF when a text-processing workflow needs one line-ending convention. Apply this only to text whose content permits that…
Create a conservative display filename
For a generated download label, use a conservative filename policy and a fallback. Replacing problematic characters can improve portability, but it is not a…
Hash a small byte buffer with Web Crypto
Use crypto.subtle.digest to compute a SHA-256 digest of a small byte buffer. The Web Crypto digest operation accepts bytes; encode text explicitly when text is the…
Merge exported records by a stable key
Use a Map to apply later records as replacements for earlier records sharing the same ID. Decide whether an update replaces the whole record or merges individual…
Sort exported records with a deterministic tie key
When generating a comparison-friendly report, sort by an explicit primary field and a stable secondary identifier. A tie key makes the output less dependent on…
Read a user-selected text file in the browser
Use a file input and File.text to read a file the user deliberately selected. Validate size and parse errors before displaying imported content.
Treat a file’s MIME label as a hint
Do not treat File.type or a filename extension as proof of content. A file object can carry an inaccurate or empty MIME label; actual parsing and format validation…
No matching articles. Try another title or topic.