{"id":31158956,"url":"https://github.com/fschaefer/json-to-compact","last_synced_at":"2026-06-28T22:31:47.549Z","repository":{"id":315402450,"uuid":"1058811352","full_name":"fschaefer/json-to-compact","owner":"fschaefer","description":"A compact JSON serializer/deserializer with token savings and bidirectional conversion","archived":false,"fork":false,"pushed_at":"2025-09-18T10:26:37.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-18T12:38:59.725Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fschaefer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-17T15:23:04.000Z","updated_at":"2025-09-18T10:26:43.000Z","dependencies_parsed_at":"2025-09-21T16:15:23.982Z","dependency_job_id":null,"html_url":"https://github.com/fschaefer/json-to-compact","commit_stats":null,"previous_names":["fschaefer/json-to-compact"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/fschaefer/json-to-compact","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschaefer%2Fjson-to-compact","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschaefer%2Fjson-to-compact/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschaefer%2Fjson-to-compact/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschaefer%2Fjson-to-compact/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fschaefer","download_url":"https://codeload.github.com/fschaefer/json-to-compact/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fschaefer%2Fjson-to-compact/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34906700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-28T02:00:05.809Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-09-19T00:54:59.769Z","updated_at":"2026-06-28T22:31:47.530Z","avatar_url":"https://github.com/fschaefer.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ⚠️ Experimental Warning\n\nThis is an **experimental project vibe coded exclusively with Sonoma Dusk Alpha** - I just told the AI to code for me. It explores techniques for noisy JSON optimization in AI-driven applications. **Use at your own risk!**\n\n# jsonToCompact\n\nA high-performance, bidirectional JSON serializer/deserializer that converts standard JSON to the Compact Format, reducing token usage by 8-20% while maintaining full fidelity with the original JSON structure.\n\nThis library was specifically designed to optimize JSON payloads in MCP (Model Context Protocol) servers, where reducing token count is crucial for efficient communication with AI models and language processing systems.\n\n## Features\n\n- 🚀 **Token Savings**: 8-20% reduction in token usage compared to standard JSON\n- 🔄 **Bidirectional**: Both serialize (JSON → Compact Format) and parse (Compact Format → JSON)\n- 🛡️ **Safe**: Protection against circular references and excessive recursion\n- 🌍 **Unicode Support**: Full Unicode character support\n- 📦 **TypeScript**: Complete TypeScript definitions included\n- 🧪 **Basic Testing**: Includes a test suite for core functionality, but may contain bugs due to experimental nature\n\n## Installation\n\n```bash\nnpm install json-to-compact\n```\n\n## Usage\n\n### JavaScript\n\n```javascript\nconst { jsonToCompact, compactToJson } = require('json-to-compact');\n\nconst obj = {\n  name: 'test',\n  nested: { arr: [1, 'two', true] },\n  special: 'Hello 🌍!'\n};\n\nconst compact = jsonToCompact(obj);\n// Output: {name test nested{arr[1 two true]} special \"Hello 🌍!\"}\n\nconst parsed = compactToJson(compact);\n// Output: { name: 'test', nested: { arr: [1, 'two', true] }, special: 'Hello 🌍!' }\n```\n\n### TypeScript\n\n```typescript\nimport { jsonToCompact, compactToJson, JsonValue } from 'json-to-compact';\n\nconst obj: JsonValue = {\n  users: [\n    { id: 1, name: 'Alice' },\n    { id: 2, name: 'Bob' }\n  ]\n};\n\nconst compact: string = jsonToCompact(obj);\nconst parsed: JsonValue = compactToJson(compact);\n```\n\n## API Reference\n\n### `jsonToCompact(obj, options?)`\n\nSerializes a JavaScript object to compact string format.\n\n**Parameters:**\n- `obj` (JsonValue): The object to serialize\n- `options` (JsonToCompactOptions, optional):\n  - `maxDepth` (number): Maximum recursion depth (default: 100)\n\n**Returns:** `string` - Compact string representation\n\n**Throws:** `Error` if input is invalid or recursion limit exceeded\n\n### `compactToJson(compactStr)`\n\nParses a compact string format back to JavaScript object.\n\n**Parameters:**\n- `compactStr` (string): The compact string to parse\n\n**Returns:** `JsonValue` - Parsed JavaScript object\n\n**Throws:** `Error` if input is invalid\n\n## Compact Format Specification\n\nThe Compact Format is a space-optimized serialization format designed for token-efficient JSON transmission. It follows these transformation rules:\n\n**Important:** Unquoted strings with spaces are treated as single tokens until the next separator (space after value, or structure delimiter).\n\n- **Objects**: `{key1 value1 key2 value2 ...}` - Keys and values separated by spaces, no colons or commas\n- **Arrays**: `[item1 item2 item3 ...]` - Elements separated by spaces, no commas\n- **Strings**:\n  - Unquoted if safe: Match `/^[a-zA-Z0-9\\-\\._\\u0080-\\uFFFF]+$/u` (alphanumeric, hyphen, dot, underscore, Unicode letters)\n  - Quoted otherwise: Standard JSON string escaping with double quotes\n- **Numbers**: Unquoted numeric values (integers and floats)\n- **Booleans**: `true` or `false` (unquoted)\n- **Null**: `null` (unquoted)\n\n### Example Transformation\n\nOriginal JSON:\n```json\n{\n  \"name\": \"John Doe\",\n  \"age\": 30,\n  \"active\": true,\n  \"tags\": [\"dev\", \"ai\"],\n  \"special\": \"Hello \\\"world\\\"!\"\n}\n```\n\nCompact Format:\n```\n{name \"John Doe\" age 30 active true tags[dev ai] special \"Hello \\\"world\\\"!\"}\n```\n\n**Note:** In this example, \"John Doe\" is quoted because it contains a space. Unquoted strings cannot contain spaces; they end at the next space or delimiter.\n\nThis format reduces token count while maintaining full parseability back to the original structure.\n## Development\n\n### Available Scripts\n\n- **`npm test`**: Runs the comprehensive test suite using Node.js.\n- **`npm run build`**: Compiles TypeScript source to JavaScript, minifies the output using Terser, and creates a production bundle in the `dist/` directory.\n- **`npm run prepublishOnly`**: Automatically runs the build script before publishing to npm.\n- **`npm run clean`**: Removes build artifacts (`dist/`) and `node_modules` directory for a clean workspace.\n\nTo get started with development:\n\n```bash\nnpm install\nnpm run build\nnpm test\n```\n\n## Author\n\n**Sonoma Dusk Alpha** - I just told the AI to code for me.\n\n## License\n\nMIT License - see LICENSE file for details.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffschaefer%2Fjson-to-compact","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffschaefer%2Fjson-to-compact","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffschaefer%2Fjson-to-compact/lists"}