JSON vs JS Objects: What Differs and What Changes When You Convert

JSON is a text format; a JavaScript object is a live value in memory. Learn the syntax differences, what JSON.stringify drops, and how to check output before use.

JSON and JavaScript objects look alike, which is why they get confused. They are different things. JSON is a text format for exchanging data, defined by RFC 8259 and ECMA-404. A JavaScript object is a value that exists inside a running program. Converting one to the other is a transformation, and it can quietly drop or reshape data. This guide explains what that conversion changes and how to check whether the result will work where you plan to use it.

The short answer

JSON is a string that follows strict rules. A JavaScript object is a data structure that can hold almost anything the language supports, including functions, dates, undefined and references to other objects. Every valid JSON document can be read into JavaScript. Not every JavaScript object can be written out as JSON without loss.

Syntax differences at a glance

Feature | JSON | JavaScript object literal
What it is | Text (a string) | A value in memory, written in source code
Property names | Must be double-quoted strings | May be unquoted, single-quoted, double-quoted or computed
String quotes | Double quotes only | Single, double or backtick quotes
Trailing commas | Not allowed | Allowed
Comments | Not allowed | Allowed in source code
Value types | object, array, string, number, true, false, null | Any JavaScript value, including functions, undefined, Symbol, BigInt, Date, Map and Set
Special numbers | No NaN, Infinity, hex, leading zeros or leading plus sign | All are valid number syntax
Methods and getters | Not representable | Allowed

The table shows why pasting an object copied from JavaScript source code into a JSON validator often fails. The usual causes are unquoted keys, single quotes, trailing commas and comments.

What converting between them actually changes

In JavaScript, JSON.stringify turns a value into JSON text and JSON.parse turns JSON text back into a value. The language specification documents the following behavior for these functions. Each item can change what your data means.

  • Object properties whose value is undefined, a function or a Symbol are left out entirely.
  • In arrays, those same values become null, which keeps the array length but changes the content.
  • NaN, Infinity and -Infinity become null.
  • Date objects become ISO 8601 strings through their toJSON method. JSON.parse does not turn them back into dates.
  • Map and Set instances become empty objects, so their contents are lost.
  • BigInt values cause a TypeError unless you supply a custom conversion.
  • Circular references cause a TypeError.
  • Symbol-keyed and non-enumerable properties are ignored.
  • Class instances lose their prototype. After a round trip you get plain objects without methods.
const user = {
  id: 42,
  name: 'Ada',
  tags: ['admin',],
  lastLogin: new Date('2026-01-15T09:30:00Z'),
  nickname: undefined,
  greet() { return 'hi'; },
};

JSON.stringify(user, null, 2);
{
  "id": 42,
  "name": "Ada",
  "tags": [
    "admin"
  ],
  "lastLogin": "2026-01-15T09:30:00.000Z"
}

In this example the nickname and greet properties are gone, the trailing comma is gone, and lastLogin is now a string. Parsing this text back gives an object whose lastLogin is a string, not a Date. If your code needs a Date, convert it explicitly, for example with the reviver argument of JSON.parse.

Edge cases that also affect meaning

  • Large integers: JavaScript numbers are double-precision floats, so integers above 2^53 lose precision when parsed. For example, JSON.parse('{"id": 9007199254740993}') returns an id of 9007199254740992. If IDs can be that large, send them as strings.
  • Duplicate keys: RFC 8259 says names should be unique and warns that parsers behave unpredictably when they are not. JSON.parse keeps the last value. Other parsers may not, so treat duplicate keys as an error to fix.
  • The proto key: in an object literal, proto: value sets the prototype. In JSON.parse it creates an ordinary own property. The same-looking text can therefore produce different results depending on how it is read.

Does formatting or minifying change the data?

Pretty-printing and minifying only change the whitespace between tokens. JSON treats that whitespace as insignificant, so the data stays the same. Whitespace inside string values is part of the data and must be preserved. A formatter that also sorts keys, normalizes numbers or re-encodes characters is doing more than formatting. Check what a tool does before you trust that its output matches its input.

Will the output work where you paste it?

JSON text that is valid when produced can stop being valid after copying and pasting. These are the common causes, all based on the JSON grammar.

  • Smart quotes: word processors, chat apps and some web pages swap straight double quotes for curly ones. JSON accepts only the straight double quote.
  • Unusual whitespace: JSON allows only space, tab, line feed and carriage return between tokens. A non-breaking space copied from a web page makes the document invalid, and it is hard to see.
  • Byte order mark: RFC 8259 says JSON text must not begin with a BOM. JSON.parse treats a leading BOM as invalid.
  • Encoding: RFC 8259 requires UTF-8 for JSON exchanged between systems that are not part of a closed ecosystem. Saving in another encoding can corrupt non-ASCII characters.
  • Comment-tolerant formats: some configuration files accept comments or trailing commas through extensions such as JSONC or JSON5. Text written for those formats may be rejected by a strict JSON parser, and the reverse can also happen. Check what the destination expects.

Before relying on transformed output, run it through the parser the destination will actually use, or a strict validator. Passing one tool does not guarantee another will accept it.

For readability, indented JSON is easier to scan visually than minified JSON. How screen readers announce brackets, quotes and indentation depends on the screen reader and its punctuation settings. No test results were available for this guide, so check with the assistive technology your readers use.

Handling sensitive data with online formatters

Pasting JSON into a web-based formatter or validator may send it to a third-party server, depending on how the tool is built. Payloads often contain API keys, access tokens, personal data or internal hostnames. Unless a tool's documentation confirms that processing stays in your browser, assume it does not. Options that stay on your machine include JSON.parse in a browser developer console, your code editor's formatter, or command-line tools such as jq or Python's json.tool module. If you must use an external service, remove or replace secrets first.

Choosing by situation

  • Sending data over a network, storing it in a file or passing it between languages: use JSON.
  • Working with data inside a JavaScript program: use objects, and convert at the boundary.
  • Data includes dates, Maps, Sets, BigInt or class instances: plan an explicit conversion in both directions instead of relying on default JSON.stringify output.
  • Configuration files that need comments: use the format the tool documents, whether that is strict JSON, JSONC, JSON5 or something else.
  • Copying a snippet from JavaScript source into a JSON-only destination: quote all keys with double quotes, convert single quotes, remove trailing commas and comments, then validate.

Limits of this guide

The behavior described here comes from the JSON specifications and the documented semantics of JSON.stringify and JSON.parse in JavaScript. No measurements or tool-specific test results were provided. Parsers in other languages, and individual online formatters, may differ on duplicate keys, number precision and non-standard extensions. Verify against the tools you actually use.