{"id":11178,"library":"json-typescript","title":"JSON-typescript Basic Type Definitions","description":"This package provides fundamental TypeScript type definitions specifically for JSON objects. Its primary purpose is to enable compile-time validation of JSON structures, ensuring that data conforms to expected shapes like `JSONValue` or `JSONObject`. The package is currently at version 1.1.2, with its last release in March 2019, indicating an inactive development cadence. Unlike more advanced libraries that generate JSON schemas from TypeScript types (e.g., `json-schema-to-typescript`) or provide runtime object mapping (e.g., `json2typescript`), `json-typescript` focuses solely on offering basic structural types for static analysis. It's suitable for projects needing straightforward type enforcement for incoming or outgoing JSON data at compile time.","status":"abandoned","version":"1.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/mike-north/json-typescript","tags":["javascript","jsonapi","typescript"],"install":[{"cmd":"npm install json-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add json-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-typescript","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This imports all type definitions under the `_JSON` namespace. Ensure your TypeScript project is configured for ESM if encountering issues with CommonJS `require`.","wrong":"const _JSON = require('json-typescript');","symbol":"All types as namespace","correct":"import * as _JSON from 'json-typescript';"},{"note":"Use the `import type` syntax for explicitly importing only type definitions, which is a best practice in modern TypeScript to avoid bundling unnecessary runtime code.","wrong":"import { Value } from 'json-typescript'; // Older TS or mixing type and value imports\nimport * as { Value } from 'json-typescript'; // Incorrect syntax","symbol":"Value","correct":"import type { Value } from 'json-typescript';"},{"note":"Aliasing types like `Object` to `JSONObject` is common to prevent naming conflicts with JavaScript's global `Object`. Use `import type` for explicit type-only imports.","wrong":"import { Object as JSONObject } from 'json-typescript'; // Older TS or mixing type and value imports\nimport * as { Object as JSONObject } from 'json-typescript'; // Incorrect syntax","symbol":"Object","correct":"import type { Object as JSONObject } from 'json-typescript';"}],"quickstart":{"code":"npm install --save-dev json-typescript\n\n// tsconfig.json might need:\n// {\n//   \"compilerOptions\": {\n//     \"moduleResolution\": \"node\",\n//     \"esModuleInterop\": true\n//   }\n// }\n\nimport type { Value as JSONValue, Object as JSONObject } from 'json-typescript';\n\n// ✅ This should be OK: a valid JSON structure\nlet validDoc: JSONValue = {\n  data: {\n    type: 'articles',\n    id: '1',\n    attributes: {\n      title: 'My Article',\n      content: 'Hello World!'\n    }\n  },\n  meta: {\n    timestamp: new Date().toISOString()\n  }\n};\n\n// ⛔️ This should NOT be OK (functions are not allowed in JSONValue)\n// let invalidDocWithFunction: JSONValue = {\n//   foo() { return 'bar'; }\n// };\n\n// ⛔️ This should NOT be OK (Array is not a JSONObject, it's a JSONValue)\n// let invalidDocAsArray: JSONObject = [];\n\n// Correct usage of JSONObject:\nlet myJsonObject: JSONObject = {\n  key1: 'value1',\n  key2: 123,\n  key3: true,\n  key4: null,\n  key5: { nested: 'object' },\n  key6: ['array', 456]\n};\n\nconsole.log('Valid JSON Document:', validDoc);\nconsole.log('My JSON Object:', myJsonObject);\n","lang":"typescript","description":"Demonstrates installation and basic usage of JSON-typescript for compile-time validation of JSON structures, highlighting correct and incorrect type assignments."},"warnings":[{"fix":"For new projects or those requiring robust JSON schema validation or runtime type checking, consider actively maintained alternatives like `json-schema-to-typescript`, `typescript-json-schema` for schema generation, or `json2typescript` for runtime deserialization. If continuing to use this package, thoroughly test compatibility with your TypeScript version.","message":"The `json-typescript` package has not been updated since March 2019. Its type definitions may not be fully compatible with newer TypeScript versions (e.g., TypeScript 4.x, 5.x) or may lack support for modern ECMAScript/JSON features and stricter type-checking configurations. This could lead to unexpected type errors or less precise type inference compared to actively maintained alternatives.","severity":"gotcha","affected_versions":">=1.1.2"},{"fix":"Always use `import type { Value, Object } from 'json-typescript';` for named type imports, or `import type { Value as JSONValue, Object as JSONObject } from 'json-typescript';` if aliasing. The `import * as ...` syntax is for namespace imports, not for destructuring named exports.","message":"The README contains an incorrect import syntax example: `import * as { Value as JSONValue, Object as JSONObject } from 'json-typescript';`. This is syntactically invalid for named type imports in TypeScript.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"For named type imports, use `import type { Value, Object } from 'json-typescript';` or `import type { Value as JSONValue, Object as JSONObject } from 'json-typescript';`.","cause":"Using the incorrect import syntax `import * as { ... } from 'json-typescript';` shown in the package's README, which is not valid JavaScript or TypeScript for named imports.","error":"SyntaxError: Unexpected token {"},{"fix":"Ensure `tsconfig.json` has `\"module\": \"esnext\"` (or compatible), `\"moduleResolution\": \"node\"`, and `\"esModuleInterop\": true`. If using CommonJS, direct `require` might not provide type inference and `import` should still be preferred for type safety. Reinstall `@types/json-typescript` if it were a separate types package (not applicable here as it ships its own types).","cause":"Attempting to import the package in a CommonJS context or without proper `tsconfig.json` setup for module resolution, especially with older TypeScript versions or when `esModuleInterop` is not enabled.","error":"Cannot find module 'json-typescript' or its corresponding type declarations."}],"ecosystem":"npm"}