{"name":"is-json","version":"3.0.0","keywords":["json","validation","is-json","typescript"],"author":{"name":"@joaquimserafim"},"license":"ISC","_id":"is-json@3.0.0","maintainers":[{"name":"quim","email":"joaquim.serafim@gmail.com"}],"homepage":"https://github.com/joaquimserafim/is-json#readme","bugs":{"url":"https://github.com/joaquimserafim/is-json/issues"},"dist":{"shasum":"ccca62cab887f3cb885548fd66745de39d7d092c","tarball":"http://registry-npm.ywwl.com/is-json/download/is-json-3.0.0.tgz","fileCount":9,"integrity":"sha512-E9Iw+39kCXzx7G1+W41tiPn7jPq944gm+gH/pn4wgANV9NH5u7Wi9LKF61nPlyw691nFUg1ykhExqhUeU+Gqzw==","signatures":[{"sig":"MEYCIQDR2ZNWzs5uL5UZ++Cg2GJIZRQTMyUAWFDEK8kv0pK6RgIhALGHawMjzWPqdjrySzbFU15QqPx2J1uovYhx50pgZsgt","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":16530,"size":4174,"noattachment":false,"key":"/is-json/-/is-json-3.0.0.tgz"},"main":"./dist/index.cjs","type":"module","types":"./dist/index.d.ts","module":"./dist/index.js","engines":{"node":">=18"},"exports":{".":{"types":"./dist/index.d.ts","import":"./dist/index.js","require":"./dist/index.cjs"}},"gitHead":"e4d83b1f143b2ad0b3968a7923929e9eaaa657b0","scripts":{"lint":"biome check .","test":"vitest run","build":"tsup","format":"biome check --write .","typecheck":"tsc --noEmit","test:watch":"vitest","test:coverage":"vitest run --coverage","prepublishOnly":"pnpm typecheck && pnpm lint && pnpm test && pnpm build"},"_npmUser":{"name":"quim","email":"joaquim.serafim@gmail.com"},"repository":{"url":"git+https://github.com/joaquimserafim/is-json.git","type":"git"},"_npmVersion":"10.9.8","description":"Check if a value is a valid JSON object/array string (or a plain object), without try/catch on the caller side.","directories":{},"_nodeVersion":"22.22.3","_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.5.1","vitest":"^4.1.7","typescript":"^6.0.3","@types/node":"^25.9.1","@biomejs/biome":"^2.4.15","@vitest/coverage-v8":"^4.1.7"},"_npmOperationalInternal":{"tmp":"tmp/is-json_3.0.0_1779837023547_0.5969226839639934","host":"s3://npm-registry-packages-npm-production"},"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":1779837023693,"_cnpm_publish_time":1779837023693,"dist-tags":{"latest":"3.0.1"}}