The two built-in methods
const text = '{"id": 42, "name": "Ada", "tags": ["a", "b"]}';
const data = JSON.parse(text); // string -> object
data.id; // 42
Array.isArray(data.tags); // true
const back = JSON.stringify(data); // object -> string
const pretty = JSON.stringify(data, null, 2);No import, no dependency, no polyfill — JSON is a language built-in available in every browser and every Node version. Anything that promises to convert a string to a JSON object in JavaScript is wrapping these two methods.
Parse safely
function safeParse(text) {
try {
return { ok: true, value: JSON.parse(text) };
} catch (err) {
return { ok: false, error: err.message };
}
}JSON.parse throws a SyntaxError on bad input, so an unguarded call in a request handler will take down the whole response. Wrap it. Newer runtimes also offerJSON.parse's reviver argument, useful for turning ISO date strings back intoDate objects during the walk instead of in a second pass.
Two things stringify does quietly
JSON.stringify({ a: undefined, b: () => 1, c: NaN, d: new Date() });
// {"c":null,"d":"2026-08-17T00:00:00.000Z"}First, undefined and functions are dropped from objects entirely — in arrays they become null, which shifts nothing but surprises everyone. Second,NaN and Infinity serialize as null, because JSON has no way to express them. A Date becomes an ISO string, and BigInt throws outright.
Double-encoded payloads
let value = JSON.parse(raw);
while (typeof value === "string") {
value = JSON.parse(value);
}If JSON.parse returns a string rather than an object, the payload was stringified more than once — normal for values pulled out of logs, message queues or a database text column. The converter above unwraps these automatically.
Node, jQuery and TypeScript
In Node.js the methods are identical; read the file withfs.readFile and parse the contents. In jQuery,$.parseJSON is deprecated and $.getJSON already parses for you, so no manual step is needed. In TypeScript, remember thatJSON.parse is typed as returning any — every property access after it is unchecked. Validating with a schema library converts an unknown blob into a value the compiler can actually reason about, which is worth the extra dependency on any input you did not produce.
Large numbers lose precision
JavaScript numbers are IEEE 754 doubles, so any integer beyondNumber.MAX_SAFE_INTEGER — about 9 quadrillion — cannot be represented exactly. A 64-bit ID from a backend arrives, gets rounded, and no longer matches the record it came from.JSON.parse does this silently; nothing warns you.
The practical fix is to have the API send such IDs as strings and never do arithmetic on them. If you cannot change the API, newer engines support a reviver that receives the original source text for each value, letting you construct a BigInt instead. Note thatJSON.stringify throws on BigInt rather than guessing, so you will need a matching replacer on the way out.
Parsing is not free
On large payloads, JSON.parse blocks the main thread, and on a slow device a multi-megabyte response is a visible freeze. If you are parsing something that big in a browser, do it in a Web Worker, or request less data. On the server, prefer streaming — Node'sres.json() buffers the whole body first, which is a memory ceiling and a denial-of-service surface on any endpoint that accepts uploads.
One last habit worth forming: never build JSON with string concatenation. Every value you splice in by hand is an escaping bug waiting for the first apostrophe. Build an object and letJSON.stringify serialize it — that is what it is for, and it never gets the escaping wrong.
Naming, briefly
Convert string to JSON in JavaScript, javascript string to json,convert string to JSON object in JavaScript, or transform string to JSON JavaScript-side — all one method, JSON.parse. The reverse, whether you call it JavaScript object to JSON string or convert object to string JavaScript, isJSON.stringify. Node.js, jQuery and TypeScript all use the same two, so a snippet written for one runs unchanged in the others. Before integrating into code, use thefree string to JSON online converter above to confirm the payload parses correctly.