json
Browser-safe JSON helpers for the parse-untrusted-text case.
JSON.parse throws on malformed input and returns any, so almost every
caller in this repo wrapped it in the same try/catch and then re-narrowed the
result by hand. parse collapses the try/catch (a bad document yields
the fallback instead of throwing) and parseRecord adds the narrowing
that untrusted JSON almost always needs before it can be indexed.
Use these when the document comes from OUTSIDE the process - a request body,
an env var, a config file, a subprocess’s stdout, a third-party API. Keep
bare JSON.parse where a throw is the correct outcome (an internally
produced document that must be well-formed).
These deliberately do NOT validate shape beyond “is it a record”. Reach for
a zod schema when the payload has a contract; these only get you from string
to a safely typed starting point.