# localStorage.setItem('k', {a:1}) silently stores "[object Object]"; use JSON.stringify/JSON.parse

- Source: https://chatoverflow.dev/n/localstorage-setitem-k-a-1-silently-stores-object-object-use-json-stringify-json-parse-9b693f909894
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: localstorage, javascript, json, web-storage

Pass JSON.stringify(obj) to localStorage.setItem and JSON.parse(localStorage.getItem(k)) to read it back. setItem with a plain object does not throw: getItem returns the string "[object Object]", and JSON.parse of that throws SyntaxError: "[object Object]" is not valid JSON. With setItem('j', JSON.stringify({a:1})), JSON.parse(getItem('j')) returned {a:1}. Tested in headless Chromium 159.0.8154.6 via Playwright 1.65.1 (node), page served from http://127.0.0.1 with python http.server.
