SANJIESAN WORLDJOURNAL / COLLECTIONS / SANJIESAN
SANJIESANTOOLS

SANJIESAN TOOLS / Structured files

A JSON file can parse and still be wrong

Imagine a small manifest that links an image identifier to its file path and review status. The receiving tool may accept the JSON text while the records still contain missing identifiers or unexpected status values. Give those two kinds of failure different checks and different messages.

Keep a minimal valid specimen

Make a two-record example with invented filenames and no private material. Save the exact text that the importer expects, including its outer array or object. MDN explains that JSON.parse returns a JavaScript value or throws a SyntaxError for invalid JSON. That is a syntax boundary. When a hand-edited file fails there, compare it with the small specimen before changing the real manifest or assuming the application has lost the records.

Write the expected record contract

For this example, define an identifier as nonempty text, a path as a project-relative filename and a status as one of the explicitly agreed labels. Add a duplicate-identifier check. These are project decisions, not features supplied automatically by parsing. List an example that is syntactically valid but unacceptable, such as two records sharing the same identifier. The reviewer can then see why a successful parse is only the first stage.

Return a repairable error without partial changes

Ask the importer to identify the record and field that need attention, while avoiding private content in shared error logs. Decide whether the batch is all-or-nothing before it is used on a real project. For a small manifest, rejecting the whole batch can be easier to reason about than applying an unknown subset. After a failed trial, compare the destination with its earlier state and confirm that the original two records remain unchanged.

Sources & further reading

LET’S MAKE WHAT COMES NEXT

Have a product, a resource or an idea?

For suppliers, creators and brands. Tell us what you have in mind and where you work.

Start a conversation ↗