{"name":"is-json","version":"3.0.1","description":"Check if a value is a valid JSON object/array string (or a plain object), without try/catch on the caller side.","type":"module","main":"./dist/index.cjs","module":"./dist/index.mjs","types":"./dist/index.d.mts","exports":{".":{"import":{"types":"./dist/index.d.mts","default":"./dist/index.mjs"},"require":{"types":"./dist/index.d.cts","default":"./dist/index.cjs"}}},"engines":{"node":">=18"},"scripts":{"build":"tsup && mv dist/index.d.ts dist/index.d.mts","typecheck":"tsc --noEmit","lint":"biome check .","format":"biome check --write .","test":"vitest run","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"pnpm typecheck && pnpm lint && pnpm test && pnpm build"},"keywords":["json","validation","is-json","typescript"],"author":{"name":"@joaquimserafim"},"license":"ISC","repository":{"type":"git","url":"git+https://github.com/joaquimserafim/is-json.git"},"bugs":{"url":"https://github.com/joaquimserafim/is-json/issues"},"homepage":"https://github.com/joaquimserafim/is-json#readme","devDependencies":{"@biomejs/biome":"^2.4.15","@types/node":"^25.9.1","@vitest/coverage-v8":"^4.1.7","tsup":"^8.5.1","typescript":"^6.0.3","vitest":"^4.1.7"},"_id":"is-json@3.0.1","gitHead":"6e2ebf6c0eb45793802793ce79e21834cee1e229","_nodeVersion":"22.22.3","_npmVersion":"10.9.8","dist":{"integrity":"sha512-fB9XwB2tyn3KSM9NK7mpqgWT4fG3ranAVCmWYEaubajNyILOPmdcMxFnaTy/Qx91RQs+VpTJCnY2BHtVCPAPyQ==","shasum":"ecfeefbaea31cab8ccb844bc48a68738f3593a48","tarball":"http://registry-npm.ywwl.com/is-json/download/is-json-3.0.1.tgz","fileCount":9,"unpackedSize":17234,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQCgQ84uTSSAH8UqgPsQ3RZ04KKJkVgKlh804aTmmwfI6QIhAOzS425RBgh1gEzdAf23yT/6I7f+q7g261thsLZmuAZb"}],"size":4443,"noattachment":false,"key":"/is-json/-/is-json-3.0.1.tgz"},"_npmUser":{"name":"quim","email":"joaquim.serafim@gmail.com"},"directories":{},"maintainers":[{"name":"quim","email":"joaquim.serafim@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/is-json_3.0.1_1779841750180_0.4891172550459766"},"_hasShrinkwrap":false,"readme":"# is-json\n\n[![CI](https://github.com/joaquimserafim/is-json/actions/workflows/ci.yml/badge.svg)](https://github.com/joaquimserafim/is-json/actions/workflows/ci.yml)\n[![npm version](https://img.shields.io/npm/v/is-json.svg)](https://www.npmjs.com/package/is-json)\n\nCheck whether a value is a valid JSON object/array (as a string, or a plain\nobject) — without writing a `try/catch` on the caller side.\n\n## Install\n\n```sh\nnpm install is-json\n# or\npnpm add is-json\n# or\nyarn add is-json\n```\n\n## Size\n\nZero runtime dependencies. What ships in the npm tarball:\n\n| What                                  | Raw      | Gzipped  |\n| ------------------------------------- | -------- | -------- |\n| **ESM runtime** (`index.mjs`)         | 996 B    | 407 B    |\n| **CJS runtime** (`index.cjs`)         | 1 006 B  | 418 B    |\n| **Types** (`.d.mts` / `.d.cts`)       | 2 398 B  | 678 B    |\n| Sourcemaps (debug-only, not loaded)   | 6 598 B  | 1 360 B  |\n\nOnly one of the two runtime files is loaded by your bundler / Node, so the\nreal cost in your app is a single sub-KB module.\n\n## Usage\n\n```js\nimport isJSON from \"is-json\";              // ESM\n// const isJSON = require(\"is-json\");      // CJS — same function\n\nisJSON('{\"a\":1,\"b\":[1,2,3]}');             // true\nisJSON('[{\"a\":1}, {\"b\":2}]');              // true\nisJSON('{\"a\":\"contains } brace\"}');        // true (v2 used to fail here)\n\nisJSON('not json');                        // false\nisJSON('{a:1}');                           // false (invalid JSON)\nisJSON(\"\");                                // false\nisJSON(null);                              // false\nisJSON(42);                                // false (default rejects non-strings)\n```\n\n### `passObjects` — accept plain objects directly\n\n```js\nisJSON({ a: 12, b: [1, 2, 3] });           // false (string required)\nisJSON({ a: 12, b: [1, 2, 3] }, true);     // true  (plain object accepted)\n\nisJSON([1, 2, 3], true);                   // false (arrays are not plain objects)\nisJSON(new Date(), true);                  // false (Date is not a plain object)\nisJSON(new Map(), true);                   // false\n```\n\nOnly objects whose prototype is `Object.prototype` (or `null`) qualify.\nArrays, class instances, `Date`, `Map`, etc. are rejected.\n\n### `isJSON.strict` — accept any valid JSON token\n\nThe default `isJSON` only accepts object/array shapes (a deliberate v3\nchoice — most callers want \"is this a JSON payload\"). For full RFC 8259\nvalidity (scalars at the top level), use `strict`:\n\n```js\nisJSON(\"42\");           // false  — scalar tokens rejected by default\nisJSON.strict(\"42\");    // true   — any valid JSON value\nisJSON.strict(\"true\");  // true\nisJSON.strict(\"null\");  // true\nisJSON.strict('\"hi\"');  // true\n\nisJSON.strict({ a: 1 }); // true  — plain objects also accepted\nisJSON.strict(123);      // false — non-string, non-plain-object inputs rejected\n```\n\n## API\n\n```ts\ninterface IsJSON {\n  (value: unknown, passObjects?: boolean): boolean;\n  strict: (value: unknown) => boolean;\n}\n\ndeclare const isJSON: IsJSON;\nexport default isJSON;\n```\n\n## Migrating from v2\n\n`isJSON(str, passObjects?)` and `isJSON.strict(str)` keep the same shape\nand the same `require('is-json')` / default-import ergonomics. Behaviour\nchanges that may affect you:\n\n| Scenario | v2 | v3 |\n| --- | --- | --- |\n| `isJSON('[1,2,3]')` | `false` (regex bug) | `true` |\n| `isJSON('{\"a\":\"}\"}')` | `false` (regex bug) | `true` |\n| `isJSON('{\"msg\":\"hello world\"}')` | brittle | `true` |\n| `isJSON.strict({a:1})` | `true` | `true` (preserved) |\n| `isJSON.strict('null')` | `null` (falsy) | `true` |\n| `isJSON.strict(123)` | `true` (parse coercion) | `false` |\n| `isJSON({...}, true)` accepting class instances | `true` | `false` |\n\nThe regex-based default validator from v2 has been replaced with a\n`JSON.parse`-based check, eliminating false positives and false negatives\naround braces in strings, whitespace-in-values, and nested arrays.\n\n## License\n\nISC © [@joaquimserafim](https://github.com/joaquimserafim)\n","publish_time":1779841750305,"_cnpm_publish_time":1779841750305,"dist-tags":{"latest":"3.0.1"}}