# How to Add Comments to package.json (Tested) | JSON5.dev


Source: https://json5.dev/config/package-json/

---

# JSON5 Comments in package.json: What Each Tool Does

npm, pnpm and both Yarn generations reject a `//` comment in `package.json`. Bun accepts it, then deletes it on the next edit.

The usual workaround is a `"//"` key. It works at the top level and inside `scripts`, but it breaks `npm install` inside `dependencies`. We ran each package manager on 12-01-2026 and pasted the real errors below.

If you want real comments, pnpm can read `package.json5`, and the table at the end matches each need to the method that fits.

![A package.json manifest with a handwritten note beside a dependency while package managers react to it](https://json5.dev/img/hero/config-package-json.png)

**TL;DR:** npm's docs say `package.json` "must be actual JSON, not just a JavaScript object literal", and npm 11.6.4 fails with `EJSONPARSE` on a `//` comment. Use a `"//"` key at the top level or in `scripts`, never in `dependencies` or `devDependencies`. For real comments use pnpm with `package.json5` (see [pnpm and JSON5](https://json5.dev/config/pnpm/)) or keep the notes in a README.

[Real Errors](#strict) [The "//" Key](#slash-key) [Scripts](#scripts) [package.json5](#json5) [Open Requests](#requests) [Which Method](#decide) [FAQ](#faq)

![Danger icon](https://json5.dev/images/icons/danger.png)

## What Happens When package.json Has a Comment

We put this file in an empty folder for each tool and ran its install command on 12-01-2026:

`{ // the app "name": "demo-pkg", "version": "1.0.0" }`

Tool

Accepts the comment

Real output

npm 11.6.4

![No](https://json5.dev/images/icons/no.png)

`npm error code EJSONPARSE`, then `Invalid package.json: JSONParseError: Expected property name or '}' in JSON at position 4 (line 2 column 3)` and `Note: package.json must be actual JSON, not just JavaScript.`

pnpm 12.25.1

![No](https://json5.dev/images/icons/no.png)

`derive workspace root and package manager policy` then `key must be a string at line 2 column 3`

Yarn 1.22.22

![No](https://json5.dev/images/icons/no.png)

`error SyntaxError: ...package.json: Expected property name or '}' in JSON at position 4 (line 2 column 3)`

Yarn 4.19.0

![No](https://json5.dev/images/icons/no.png)

`Syntax Error: Expected property name or '}' in JSON at position 4 (line 2 column 3)` naming the file

Bun 1.4.5

![Yes](https://json5.dev/images/icons/yes.png)

`bun install` finished with no error on this file

The npm and both Yarn messages carry the same sentence as the Node.js `JSON.parse` error. The npm line "Expected property name or '}'" points at the first comment, so it reads like a broken key. Look for a comment or a [trailing comma](https://json5.dev/glossary/#trailing-comma). The [comments in JSON](https://json5.dev/comments-in-json/) page shows the same error for any JSON file.

The pnpm message is shorter and does not name the file. We ran it through `npx --yes pnpm@latest`, which resolved to 12.25.1; Yarn 1 came from `npx --yes yarn@latest`, and Yarn 4 from `npx --yes @yarnpkg/cli-dist@latest`, because `yarn@latest` resolved to 1.22.22. Node.js was 24.22.1.

**Bun accepting it is a trap.** We added a dependency with `bun add is-even` to a commented file with an `is-odd` dependency already in it. Bun rewrote `package.json` and the `// comment` line was gone. If one teammate uses Bun and another uses npm, the file works for one of them, and the first Bun edit deletes the comment for everyone.

![Comment icon](https://json5.dev/images/icons/comment.png)

## The "//" Key Convention

A `"//"` key is valid JSON, so every tool parses it. The note is a string (or an array of strings) stored under a key that no tool uses. It is a convention, not a feature: the [npm package.json documentation](https://docs.npmjs.com/cli/v11/configuring-npm/package-json) does not mention it. Everything below is what we observed, not what is documented.

### Top level

`{ "//": "Top-level note", "name": "demo-pkg", "version": "1.0.0", "dependencies": { "is-odd": "3.0.1" } }`

`npm install` reported "added 2 packages" with no warning. Then `npm install is-even` added the dependency and left the `"//"` key and its value in place, as did `pnpm add is-even` (12.25.1) and `yarn add is-even` (1.22.22). The top-level key is safe in all three.

### Inside dependencies

`"dependencies": { "//": "is-odd is pinned: 3.0.2 broke us", "is-odd": "3.0.1" }`

This is the place people most want a note, and it fails. In `dependencies` the key is a package name, so the tools try to install a package called "//" at the version "is-odd is pinned...":

Tool

Real output

npm 11.6.4

`npm error code EINVALIDPACKAGENAME` and `Invalid package name "//" of package "//@is-odd is pinned: 3.0.2 broke us": name can only contain URL-friendly characters.` `npm ls` also fails with `ELSPROBLEMS`

pnpm 12.25.1

`ERR_PNPM_INVALID_DEPENDENCY_NAME`: the project "contains a dependency with an invalid name: "//""

Bun 1.4.5

`error: invalid dependency name "//"` and `error: //@note failed to resolve`

We did not test this case on Yarn. Treat it as unsafe there too. Put the reason for a pin in the top-level note or the README, and name the package in it: `"//": "is-odd pinned to 3.0.1: 3.0.2 broke the build"`.

### Repeated keys

JSON allows repeated keys in text, but a parser keeps one. We gave a file two top-level `"//"` keys, the first an array of two notes and the second a string, then ran `npm pkg set description=hello`. npm rewrote the file with one `"//"` key holding the last value, the string. The array was gone. The [comments in JSON](https://json5.dev/comments-in-json/) page shows the same last-one-wins result in plain Node.js. Use different key names (`"//build"`, `"//deps"`) or one array.

![Terminal icon](https://json5.dev/images/icons/terminal.png)

## Comments in Scripts and Custom Keys

In `scripts` a `"//"` key is a script that nobody runs. We tested this file:

`"scripts": { "//": "Runs the build", "//test": "node test runner", "build": "echo building" }`

`npm install` and `npm run build` worked. A plain `npm run` listed all three, the notes as entries named `//` and `//test` with the text underneath:

``Scripts available in demo-pkg@1.0.0 via `npm run`: // Runs the build //test node test runner build echo building``

That is a mild bonus: the note shows up where people look for commands. The cost is that tools which list scripts, such as editor script runners and CI dashboards, will show the notes as scripts too. We did not test those. A script key is a command name, so keep the note text out of anything you would not want a shell to run.

Some teams use a descriptive key instead of `"//"`, such as `"scripts-info"` or `"_notes"`. Any name works for the parser, so pick one convention per repository and keep it at the top level, away from `dependencies`. Fields that npm itself reads (`description`, `keywords`) are better than a note when the text is something a user should see.

![Code file icon](https://json5.dev/images/icons/code-file.png)

## package.json5 and package.yaml with pnpm

The [pnpm docs](https://pnpm.io/package_json) say "In addition to the traditional `package.json` format, pnpm also supports `package.json5`" and `package.yaml`. That is the only mainstream route to real comments in a manifest. We tested it earlier and wrote it up: [pnpm and package.json5](https://json5.dev/config/pnpm/) shows comments surviving `pnpm add`, the published tarball containing a plain `package.json`, and npm and Yarn failing on the file. Read it before you rename anything.

The short version: every developer and CI job in the repository must use pnpm, and nothing else may parse the manifest. Bots, scanners and editor integrations that look for `package.json` will not see a `package.json5`. Remember that `package.json` wins if both files exist.

![Announcement icon](https://json5.dev/images/icons/announcement.png)

## The Requests to npm, and Their Status

People have asked npm for comments in `package.json` for years. This is what each page showed on 12-01-2026; we describe status only as shown, and it can change.

Request

Opened

Status shown

[npm/cli #793](https://github.com/npm/cli/issues/793): allow JSONC or JSON5 for package.json

02-10-2020

Closed as completed on 06-02-2021 by an automated message saying npm v6 is no longer in active development and asking people to re-file against v7 or open an RFC. A comment as late as 12-31-2024 asks for it again

[npm/rfcs #291](https://github.com/npm/rfcs/issues/291): opt-in `package.json5` that npm uses to regenerate `package.json`

11-21-2020

Open, with a linked pull request also open. Latest activity shown is 10-28-2026. We saw no npm decision on the page

[npm/rfcs discussion #230](https://github.com/npm/rfcs/discussions/230): use JSON5 for package.json

09-16-2020

Marked unanswered; latest visible activity 02-02-2024. We saw no reply from an npm maintainer on the page

The objections in those threads are consistent. A contributor says in #230 that ".json means JSON. JSON5 would necessitate a different extension" and in #291 that adoption would be hard for tooling to handle. In #793 another commenter calls the change backwards incompatible because other tools would have to read the new syntax.

Evert Pot's post ["JSON5"](https://www.evertpot.com/json5/) (01-09-2023) argues the other side and names the hard part: "Plus there's the whole chicken and egg thing with needing a JSON5 parser before we have dependencies." A package manager would need a JSON5 parser built in before it can install anything, including the parser. He says he would annotate a great deal in `package.json` if npm adopted it.

![Target icon](https://json5.dev/images/icons/target.png)

## Which Method for Which Need

Your need

Method

Watch out for

One note about the whole package

Top-level `"//"` key, or `description`

Repeated `"//"` keys keep only the last

Why a dependency is pinned

A top-level note that names the package, or a README section

A `"//"` key inside `dependencies` breaks install in npm, pnpm and Bun

What a script does

`"//name"` keys in `scripts`, or a docs page

Notes appear in `npm run`; do not make them commands

Real comments beside values

`package.json5` with pnpm

npm and Yarn cannot read it; check bots and CI first

Real comments, mixed team

Generate `package.json` from a commented source in your own build

Two files to keep in sync; this is your own tooling, not an npm feature. Parse the source with [the json5 package](https://json5.dev/javascript/)

Comments that must survive Bun edits

Do not rely on `//` comments

Bun 1.4.5 deleted ours on `bun add`

Notes for people reading the repo

README, a `docs/` file, or the pull request

They can drift from the manifest, so link to them from the top-level note

More on writing notes that stay true is in [comments best practices](https://json5.dev/tutorials/comments-best-practices/), and the full list of options for other file types is on [comments in JSON](https://json5.dev/comments-in-json/).

## Comments in package.json: Common Questions

### Can package.json have comments?

Not `//` comments in npm, pnpm or Yarn, which failed in our test. Bun 1.4.5 accepted them. The npm docs say the file "must be actual JSON".

### What does the "//" key do in npm?

Nothing. It is an ordinary key that npm ignores at the top level and in `scripts`, and that npm 11.6.4 keeps when it rewrites the file. Inside `dependencies` it fails.

### Why does npm say "Expected property name or '}'"?

It is the `JSON.parse` message for a comment or other non-JSON [token](https://json5.dev/glossary/#punctuator). In our file it pointed at position 4, the start of the comment.

### Does pnpm allow comments?

In `package.json5`, yes; see [our pnpm guide](https://json5.dev/config/pnpm/). In `package.json`, pnpm 12.25.1 failed on a `//` comment.

### Will npm ever support JSON5 or JSONC?

We cannot say. The npm/rfcs request #291 was still open on 12-01-2026 with no decision shown on the page.

### Is a comment in package.json published?

A "//" key sits in the file, so it ships with the package. We did not test what registry tooling does with it. Keep notes free of internal details.

## See Also

[![Comment icon](https://json5.dev/images/icons/comment.png)

### Comments in JSON

Every option, tested

](https://json5.dev/comments-in-json/)[![pnpm logo](https://json5.dev/images/tech/pnpm.png)

### pnpm Manifests

package.json5 tested

](https://json5.dev/config/pnpm/)[![Settings icon](https://json5.dev/images/icons/settings.png)

### All Config Guides

Tools that read JSON5

](https://json5.dev/config/)

## Strip Comments From a File

Paste a commented manifest into the converter and copy back plain JSON.

[Open the Converter](https://json5.dev/tools/online-converter/)

## Sources

(10)

1.  [npm docs: package.json](https://docs.npmjs.com/cli/v11/configuring-npm/package-json)
2.  [npm docs: npm pkg](https://docs.npmjs.com/cli/v11/commands/npm-pkg) (documents that it respects existing indentation; says nothing on comments)
3.  [npm/cli issue 793: Allow jsonc or JSON5 for package.json for commenting](https://github.com/npm/cli/issues/793)
4.  [npm/rfcs issue 291: Opt-in solution to support comments in package.json](https://github.com/npm/rfcs/issues/291)
5.  [npm/rfcs discussion 230: Use JSON5 For package.json](https://github.com/npm/rfcs/discussions/230)
6.  [Evert Pot: JSON5 (01-09-2023)](https://www.evertpot.com/json5/)
7.  [pnpm docs: package.json](https://pnpm.io/package_json)
8.  [pnpm on npm](https://www.npmjs.com/package/pnpm) (12.25.1 tested)
9.  [bun on npm](https://www.npmjs.com/package/bun) (1.4.5 tested)
10.  [@yarnpkg/cli-dist on npm](https://www.npmjs.com/package/@yarnpkg/cli-dist) (Yarn 4.19.0 tested)

Last reviewed: December 1, 2026.
