{"id":30176122,"url":"https://github.com/katt/danson","last_synced_at":"2026-03-07T01:01:17.138Z","repository":{"id":298896868,"uuid":"1001465755","full_name":"KATT/danson","owner":"KATT","description":null,"archived":false,"fork":false,"pushed_at":"2025-12-20T00:59:14.000Z","size":223,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-12-22T10:59:00.038Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/KATT.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","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-06-13T12:32:20.000Z","updated_at":"2025-12-20T16:58:11.000Z","dependencies_parsed_at":"2025-12-20T06:05:51.522Z","dependency_job_id":null,"html_url":"https://github.com/KATT/danson","commit_stats":null,"previous_names":["katt/danson"],"tags_count":16,"template":false,"template_full_name":null,"purl":"pkg:github/KATT/danson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KATT%2Fdanson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KATT%2Fdanson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KATT%2Fdanson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KATT%2Fdanson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KATT","download_url":"https://codeload.github.com/KATT/danson/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KATT%2Fdanson/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30204444,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T19:07:06.838Z","status":"ssl_error","status_checked_at":"2026-03-06T18:57:34.882Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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-08-12T02:20:16.652Z","updated_at":"2026-03-07T01:01:17.126Z","avatar_url":"https://github.com/KATT.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003edanSON\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003eProgressive JSON\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\t\u003ca href=\"https://github.com/KATT/danson/blob/main/.github/CODE_OF_CONDUCT.md\" target=\"_blank\"\u003e\u003cimg alt=\"🤝 Code of Conduct: Kept\" src=\"https://img.shields.io/badge/%F0%9F%A4%9D_code_of_conduct-kept-21bb42\" /\u003e\u003c/a\u003e\n\t\u003ca href=\"https://codecov.io/gh/KATT/danson\" target=\"_blank\"\u003e\u003cimg alt=\"🧪 Coverage\" src=\"https://img.shields.io/codecov/c/github/KATT/danson?label=%F0%9F%A7%AA%20coverage\" /\u003e\u003c/a\u003e\n\t\u003ca href=\"https://github.com/KATT/danson/blob/main/LICENSE.md\" target=\"_blank\"\u003e\u003cimg alt=\"📝 License: MIT\" src=\"https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg\" /\u003e\u003c/a\u003e\n\t\u003ca href=\"http://npmjs.com/package/danson\" target=\"_blank\"\u003e\u003cimg alt=\"📦 npm version\" src=\"https://img.shields.io/npm/v/danson?color=21bb42\u0026label=%F0%9F%93%A6%20npm\" /\u003e\u003c/a\u003e\n\t\u003cimg alt=\"💪 TypeScript: Strict\" src=\"https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg\" /\u003e\n\u003c/p\u003e\n\n## About\n\ndanSON is a progressive JSON serializer and deserializer that can serialize and deserialize arbitrary objects into JSON.\n\n## Features\n\n- Streaming of `Promise`s, `AsyncIterable`s, and `ReadableStream`s\n- Custom serializers / deserializers\n- De-duplication of objects (optional)\n- Circular references\n- Serializable errors\n- Human-readable JSON output\n- Built-in serializers for common JavaScript types\n\n## Installation\n\n```shell\nnpm install danson\n```\n\n[Try the example on StackBlitz](https://stackblitz.com/github/KATT/danson/tree/main/example)\n\n## Usage\n\n### Synchronous Usage\n\n```ts\nimport { parseSync, stringifySync } from \"danson\";\n\nconst data = {\n\tfoo: \"bar\",\n};\n\nconst stringified = stringifySync(data);\n\nconst parsed = parseSync(stringified);\n\nconsole.log(parsed); // { foo: \"bar\" }\n```\n\n### Asynchronous Usage\n\n```ts\nimport { parseAsync, stringifyAsync } from \"danson\";\n\nconst sleep = (ms: number) =\u003e new Promise((resolve) =\u003e setTimeout(resolve, ms));\n\nconst data = {\n\tpromise: (async () =\u003e {\n\t\tawait sleep(1000);\n\t\treturn \"hello promise\";\n\t})(),\n};\n\nconst iterable = stringifyAsync(data);\n\nconst parsed = await parseAsync(iterable);\n//      ^? { promise: Promise\u003cstring\u003e }\n\nconsole.log(await parsed.promise); // \"hello promise\"\n```\n\n### Built-in Serializers\n\nThe `std` module provides built-in serializers for common JavaScript types that works with both synchronous and asynchronous usage.\n\nSupported types:\n\n- `BigInt`\n- `Date`\n- `Headers`\n- `Map`\n- Special numbers (`-0`, `Infinity`, `-Infinity`, `NaN`)\n- `RegExp`\n- `Set`\n- TypedArrays (`Int8Array`, `Uint8Array`, etc.)\n- `undefined`\n- `URL`\n- `URLSearchParams`\n\n```ts\nimport { parseSync, std, stringifySync } from \"danson\";\n\n// Using built-in serializers\nconst data = {\n\tdate: new Date(),\n\theaders: new Headers({\n\t\t\"Content-Type\": \"application/json\",\n\t}),\n\tmap: new Map([[\"key\", \"value\"]]),\n\tnumbers: {\n\t\tbigint: 123n,\n\t\tinfinity: Infinity,\n\t\tnegativeInfinity: -Infinity,\n\t\tnegativeZero: -0,\n\t\tnotANumber: NaN,\n\t},\n\tregexp: /foo/g,\n\tset: new Set([1, 2, 3]),\n\ttypedArray: new Int8Array([1, 2, 3]),\n\tundef: undefined,\n\turl: new URL(\"https://example.com\"),\n\turlSearchParams: new URLSearchParams(\"foo=bar\"),\n};\n\nconst stringified = stringifySync(data, {\n\tserializers: {\n\t\t...std.serializers,\n\t\t// ... your custom serializers\n\t},\n\tspace: 2,\n});\n\nconst parsed = parseSync(stringified, {\n\tdeserializers: {\n\t\t...std.deserializers,\n\t\t// ... your custom deserializers\n\t},\n});\n```\n\n### Custom Serialization\n\nYou can provide custom serializers for your own types.\n\n```ts\nimport { Temporal } from \"@js-temporal/polyfill\";\nimport { std } from \"danson\";\n\nconst stringified = stringifySync(value, {\n\tserializers: {\n\t\t...std.serializers, // use the built-in serializers (optional)\n\t\t\"Temporal.Instant\": (value) =\u003e\n\t\t\tvalue instanceof Temporal.Instant ? value.toJSON() : false,\n\t},\n});\n\nconst parsed = parseSync(stringified, {\n\tdeserializers: {\n\t\t...std.deserializers, // use the built-in deserializers (optional)\n\t\t\"Temporal.Instant\": (value) =\u003e Temporal.Instant.from(value as string),\n\t},\n});\n```\n\n#### `TransformerPair\u003cTOriginal, TSerialized\u003e`\n\nType utility for defining serializer/deserializer pairs.\n\nUsed internally but can be useful for type-safe custom serializers.\n\n```ts\nimport { Temporal } from \"@js-temporal/polyfill\";\nimport { TransformerPair } from \"danson\";\n\n// Define a type-safe transformer pair for Temporal.Instant\ntype TemporalNow = TransformerPair\u003cTemporal.Instant, string\u003e;\n\nconst serializeTemporalNow: TemporalNow[\"serialize\"] = (value) =\u003e {\n\tif (value instanceof Temporal.Instant) {\n\t\treturn value.toJSON();\n\t}\n\treturn false;\n};\n\nconst deserializeTemporalNow: TemporalNow[\"deserialize\"] = (value) =\u003e {\n\treturn Temporal.Instant.from(value);\n};\n\n// Use the transformer pair\nconst source = {\n\tinstant: Temporal.Now.instant(),\n};\n\nconst stringified = stringifySync(source, {\n\tserializers: {\n\t\t\"Temporal.Instant\": serializeTemporalNow,\n\t},\n});\n\nconst result = parseSync(stringified, {\n\tdeserializers: {\n\t\t\"Temporal.Instant\": deserializeTemporalNow,\n\t},\n});\n```\n\n## Example outputs\n\n### Streaming `Promise`s\n\n#### Promise example input\n\n```ts\nconst source = {\n\tfoo: \"bar\",\n\tpromise: (async () =\u003e {\n\t\tawait sleep(1000);\n\t\treturn \"hello promise\";\n\t})(),\n};\n\nconst stringified = stringifySync(source, {\n\tspace: 2,\n});\nfor await (const chunk of stringified) {\n\tconsole.log(chunk);\n}\n```\n\n#### Promise example output\n\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- eslint-disable --\u003e\n\n```jsonc\n{\n\t\"json\": {\n\t\t\"foo\": \"bar\",\n\t\t\"promise\": {\n\t\t\t\"_\": \"$\", // informs the deserializer that this is a special type\n\t\t\t\"type\": \"Promise\", // it is a Promise\n\t\t\t\"value\": 1, // index of the Promise that will come later\n\t\t}\n\t}\n}\n```\n\n```jsonc\n[\n\t1, // index of the Promise\n\t0, // Promise succeeded (0 = success, 1 = failure)\n\t{\n\t\t\"json\": \"hello promise\"\n\t}\n]\n```\n\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- eslint-enable --\u003e\n\n### Streaming `AsyncIterable`s\n\n#### AsyncIterable example input\n\n```ts\nconst source = {\n\tasyncIterable: (async function* () {\n\t\tyield \"hello\";\n\t\tyield \"world\";\n\n\t\treturn \"done\";\n\t})(),\n};\n\nconst stringified = stringifySync(source, {\n\tspace: 2,\n});\nfor await (const chunk of stringified) {\n\tconsole.log(chunk);\n}\n```\n\n\u003c!-- prettier-ignore-start --\u003e\n\u003c!-- eslint-disable --\u003e\n\n#### AsyncIterable example output\n\n```jsonc\n{\n\t\"json\": {\n\t\t\"foo\": \"bar\",\n\t\t\"asyncIterable\": {\n\t\t\t\"_\": \"$\",\n\t\t\t\"type\": \"AsyncIterable\",\n\t\t\t\"value\": 0\n\t\t}\n\t}\n}\n```\n\n```jsonc\n[\n\t0,\n\t0,\n\t{\n\t\t\"json\": \"world\"\n\t}\n]\n```\n\n```jsonc\n[\n\t0, // index of the AsyncIterable\n\t2,\n\t{\n\t\t\"json\": \"done\"\n\t}\n]\n```\n\n\n\u003c!-- prettier-ignore-end --\u003e\n\u003c!-- eslint-enable --\u003e\n\n## API Reference\n\n### `stringifySync(value: unknown, options?: StringifyOptions): string`\n\nSerializes a value into a JSON string.\n\n### `parseSync\u003cT\u003e(value: string, options?: ParseOptions): T`\n\nDeserializes a JSON string into a value.\n\n### `serializeSync(value: unknown, options?: StringifyOptions): SerializeReturn`\n\nSerializes a value into a `JSON.stringify`-compatible format.\n\n### `deserializeSync\u003cT\u003e(value: SerializeReturn, options?: ParseOptions): T`\n\nDeserializes from a `SerializeReturn` object into a value.\n\n### `stringifyAsync(value: unknown, options?: StringifyOptions): AsyncIterable\u003cstring, void\u003e`\n\nSerializes a value into a stream of JSON strings asynchronously.\n\n### `parseAsync\u003cT\u003e(value: AsyncIterable\u003cstring, void\u003e, options?: ParseOptions): Promise\u003cT\u003e`\n\nDeserializes a stream of JSON strings into a value asynchronously.\n\n### `serializeAsync(value: unknown, options?: StringifyOptions): AsyncIterable\u003cunknown, void\u003e`\n\nSerializes a value into a stream of intermediate objects asynchronously.\n\n### `deserializeAsync\u003cT\u003e(value: AsyncIterable\u003cunknown, void\u003e, options?: ParseOptions): Promise\u003cT\u003e`\n\nDeserializes a stream of intermediate objects into a value asynchronously.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatt%2Fdanson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkatt%2Fdanson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkatt%2Fdanson/lists"}