{"_id":"@adllang/jsonbinding","_rev":"10-3c73fdde930b7c13b95a2e91d80c3661","name":"@adllang/jsonbinding","dist-tags":{"latest":"0.4.0"},"versions":{"0.0.1":{"name":"@adllang/jsonbinding","version":"0.0.1","license":"AGPL-3.0-or-later","_id":"@adllang/jsonbinding@0.0.1","maintainers":[{"name":"timbod7","email":"tim@dockerz.net"}],"dist":{"shasum":"e49e75dfef44e9fead1b50532b9c656d929fdb38","tarball":"https://registry.npmjs.org/@adllang/jsonbinding/-/jsonbinding-0.0.1.tgz","fileCount":8,"integrity":"sha512-WF/XFaZ3jnOKf8mg3JIFyPRp7EnrN02uCguTLnbsLBHfywdysA7CxioXCdNnlqSFvhaOpUkuTOjUYmXvY+Rf5Q==","signatures":[{"sig":"MEYCIQCiR47U0sFi/4B93SD6UQJ+MtODk7t0I16cwFK2GYgGxwIhAJ3AvtXHpTOR4+L6y9gvtlJqSfRjb2ByGLWir74LZUMQ","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":22375},"main":"index.js","types":"index.js.ts","gitHead":"42c813eed0bda12d0f4eca1d41db494f540b73d7","private":false,"scripts":{"test":"yarn vitest run","build":"yarn clean && yarn tsc && cp package.json README.md dist","clean":"rm -rf dist"},"_npmUser":{"name":"timbod7","email":"tim@dockerz.net"},"_npmVersion":"10.7.0","description":"Key features: * typescript implementation * extensible * bidirectional (ie serialization and deserialization) * errors that describe the location of parse failures * support for unions, generics and custom types * handles builtin types like `biginti` and ","directories":{},"_nodeVersion":"20.14.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"vite":"4.5.0","vitest":"^1.3.1","tsc-alias":"^1.8.3","typescript":"^5.5.3","@types/node":"^20.11.26"},"_npmOperationalInternal":{"tmp":"tmp/jsonbinding_0.0.1_1721019217980_0.8173343419109194","host":"s3://npm-registry-packages"}},"0.0.2":{"name":"@adllang/jsonbinding","version":"0.0.2","license":"AGPL-3.0-or-later","_id":"@adllang/jsonbinding@0.0.2","maintainers":[{"name":"timbod7","email":"tim@dockerz.net"}],"dist":{"shasum":"41fe2903f447253530776ff9d267eb2ee967a8a3","tarball":"https://registry.npmjs.org/@adllang/jsonbinding/-/jsonbinding-0.0.2.tgz","fileCount":8,"integrity":"sha512-sY4pksMYrqoXR4vhhdAPwDxOuY8GnLvQWcEBCrxk6SP6zaYWZbZ1vuKU02BoAvrfAXHSF+F/u0IWy5jEccmlkw==","signatures":[{"sig":"MEYCIQDjCTZVbHpL9jxjvfLuYerwi9ej7kr1g/tyRxN7QCyi4wIhAIBjmpJ00CQQ2Qc3catWjJnClqcFb7BZAxsmiD+53pR8","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":22698},"main":"index.js","types":"index.js.ts","gitHead":"29db6804d07d0190231b4d437a954a2721573f72","private":false,"scripts":{"test":"yarn vitest run","build":"yarn clean && yarn tsc && cp package.json README.md dist","clean":"rm -rf dist"},"_npmUser":{"name":"timbod7","email":"tim@dockerz.net"},"_npmVersion":"10.7.0","description":"Key features: * typescript implementation * extensible * bidirectional (ie serialization and deserialization) * errors that describe the location of parse failures * support for unions, generics and custom types * handles builtin types like `biginti` and ","directories":{},"_nodeVersion":"20.14.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"vite":"4.5.0","vitest":"^1.3.1","tsc-alias":"^1.8.3","typescript":"^5.5.3","@types/node":"^20.11.26"},"_npmOperationalInternal":{"tmp":"tmp/jsonbinding_0.0.2_1721032192486_0.3711832821188046","host":"s3://npm-registry-packages"}},"0.0.3":{"name":"@adllang/jsonbinding","version":"0.0.3","license":"AGPL-3.0-or-later","_id":"@adllang/jsonbinding@0.0.3","maintainers":[{"name":"timbod7","email":"tim@dockerz.net"}],"dist":{"shasum":"3be2c0a163e76d3ba40502a628d8b166baa96ad1","tarball":"https://registry.npmjs.org/@adllang/jsonbinding/-/jsonbinding-0.0.3.tgz","fileCount":8,"integrity":"sha512-V4S+qayWUGZ9k48APQVpQQWYrbkPAgDv1qL1LpS6Vk0t7EzEdH4lZY0D4K2KuefYrjCukRvimo8lZhhWL84Ttg==","signatures":[{"sig":"MEQCICVfqsXMfHHL7dx+LLfdZ/9T1RjTg/d8YaRbtiaEnk4VAiBq9GmXTjv5V3Opc+K++S6psaKK0aEXoBpV9NooiOvHZw==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":23868},"main":"index.js","types":"index.js.ts","gitHead":"3ec0b23c423fa62f3e02c8e351f2103318690612","private":false,"scripts":{"test":"yarn vitest run","build":"yarn clean && yarn tsc && cp package.json README.md dist","clean":"rm -rf dist"},"_npmUser":{"name":"timbod7","email":"tim@dockerz.net"},"_npmVersion":"10.7.0","description":"Key features: * typescript implementation * extensible * bidirectional (ie serialization and deserialization) * errors that describe the location of parse failures * support for unions, generics and custom types * handles builtin types like `biginti` and ","directories":{},"_nodeVersion":"20.14.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"vite":"4.5.0","vitest":"^1.3.1","tsc-alias":"^1.8.3","typescript":"^5.5.3","@types/node":"^20.11.26"},"_npmOperationalInternal":{"tmp":"tmp/jsonbinding_0.0.3_1721083098616_0.8074050331359417","host":"s3://npm-registry-packages"}},"0.1.0":{"name":"@adllang/jsonbinding","version":"0.1.0","license":"AGPL-3.0-or-later","_id":"@adllang/jsonbinding@0.1.0","maintainers":[{"name":"timbod7","email":"tim@dockerz.net"}],"homepage":"https://github.com/adl-lang/ts-jsonbinding#readme","bugs":{"url":"https://github.com/adl-lang/ts-jsonbinding/issues"},"dist":{"shasum":"5c2a4aae94f9e563f26777262bd4c9fead005170","tarball":"https://registry.npmjs.org/@adllang/jsonbinding/-/jsonbinding-0.1.0.tgz","fileCount":8,"integrity":"sha512-mqava2FNXRIG1fX+D82BN9oHHiKi2ARi8X6LTYcGsSpObsptVQZKenUFjpPa5Wrjva8A0Vv9FH7iTS2pUHtYbA==","signatures":[{"sig":"MEUCIQCqqPiTyz7pKPxYYRoRQVj+A5vxnEhykac3yabgBltw8gIgbwAXJGUHKkTaKc7qaJ05mxbyc3tWgLdqSYJY8sA0liA=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":26551},"main":"index.js","types":"index.js.ts","gitHead":"4caabe716445489985155ae26f77ad9473630df8","private":false,"scripts":{"test":"yarn vitest run","build":"yarn clean && yarn tsc && cp package.json README.md dist","clean":"rm -rf dist"},"_npmUser":{"name":"timbod7","email":"tim@dockerz.net"},"repository":{"url":"git+https://github.com/adl-lang/ts-jsonbinding.git","type":"git"},"_npmVersion":"10.7.0","description":"Key features: * typescript implementation * extensible * bidirectional (ie serialization and deserialization) * errors that describe the location of parse failures * support for unions, generics and custom types * handles builtin types like `bigint`, `Dat","directories":{},"_nodeVersion":"20.14.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"vite":"4.5.0","vitest":"^1.3.1","tsc-alias":"^1.8.3","typescript":"^5.5.3","@types/node":"^20.11.26"},"_npmOperationalInternal":{"tmp":"tmp/jsonbinding_0.1.0_1721120250911_0.8809773686309303","host":"s3://npm-registry-packages"}},"0.1.1":{"name":"@adllang/jsonbinding","version":"0.1.1","license":"MIT","_id":"@adllang/jsonbinding@0.1.1","maintainers":[{"name":"timbod7","email":"tim@dockerz.net"}],"homepage":"https://github.com/adl-lang/ts-jsonbinding#readme","bugs":{"url":"https://github.com/adl-lang/ts-jsonbinding/issues"},"dist":{"shasum":"e42920be62633efdfd4baba96c42dc928e7138dc","tarball":"https://registry.npmjs.org/@adllang/jsonbinding/-/jsonbinding-0.1.1.tgz","fileCount":8,"integrity":"sha512-t6wQxr3eeU53Egh4f5Uhy2EOLIRiE2JzHZzXhdtbQyY4rO7LijxPmtKT3sSaigxbP5G50W+RXPTpyS0KwvI6cA==","signatures":[{"sig":"MEQCIBZzuIXBg/iVQ1Q41SxEAsUjv8Am+i4VzEN802k+Bn7eAiBkebi7L+ZTVWKIH5sDf0VZ2v9LSZRAyoU/LtCj+HfViQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":26510},"main":"index.js","types":"index.js.ts","gitHead":"4caabe716445489985155ae26f77ad9473630df8","private":false,"scripts":{"test":"yarn vitest run","build":"yarn clean && yarn tsc && cp package.json README.md dist","clean":"rm -rf dist"},"_npmUser":{"name":"timbod7","email":"tim@dockerz.net"},"repository":{"url":"git+https://github.com/adl-lang/ts-jsonbinding.git","type":"git"},"_npmVersion":"10.7.0","description":"Key features: * typescript implementation * extensible * bidirectional (ie serialization and deserialization) * errors that describe the location of parse failures * support for unions, generics and custom types * handles builtin types like `bigint`, `Dat","directories":{},"_nodeVersion":"20.14.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"vite":"4.5.0","vitest":"^1.3.1","typescript":"^5.5.3","@types/node":"^20.11.26"},"_npmOperationalInternal":{"tmp":"tmp/jsonbinding_0.1.1_1721179895667_0.0704102503319941","host":"s3://npm-registry-packages"}},"0.2.2":{"name":"@adllang/jsonbinding","version":"0.2.2","license":"MIT","_id":"@adllang/jsonbinding@0.2.2","maintainers":[{"name":"timbod7","email":"tim@dockerz.net"}],"homepage":"https://github.com/adl-lang/ts-jsonbinding#readme","bugs":{"url":"https://github.com/adl-lang/ts-jsonbinding/issues"},"dist":{"shasum":"32deed7811a48dc23baf999efe5093ae4661f515","tarball":"https://registry.npmjs.org/@adllang/jsonbinding/-/jsonbinding-0.2.2.tgz","fileCount":11,"integrity":"sha512-Lskc7cx0Ed0zX1ggd900g3sXoCIDVhVpLGp8QYhR2+8jzNioJ3DQfhGZRJtZ/lUqAkJTem5CdvmDDfeo/ZeXNw==","signatures":[{"sig":"MEQCIG+gmea+gVXBJ/dPkSed+DeJ5RXLBsa5IM9aE5lddgG4AiBsqDqPjn48qDi8ffxlsnFnO1E/CL50rUvgAJLZC697wg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":54530},"main":"./script/jsonbinding.js","types":"./script/jsonbinding.d.ts","module":"./esm/jsonbinding.js","exports":{".":{"import":"./esm/jsonbinding.js","require":"./script/jsonbinding.js"}},"gitHead":"44f20c1e052cb0f8398e69827c32d562207bf4f2","scripts":{"test":"node test_runner.js"},"_npmUser":{"name":"timbod7","email":"tim@dockerz.net"},"repository":{"url":"git+https://github.com/adl-lang/ts-jsonbinding.git","type":"git"},"_npmVersion":"10.7.0","description":"A typescript library for JSON serialization","directories":{},"_nodeVersion":"20.14.0","_hasShrinkwrap":false,"devDependencies":{"picocolors":"^1.0.0","@types/node":"^20.9.0"},"_npmOperationalInternal":{"tmp":"tmp/jsonbinding_0.2.2_1731734097155_0.8195569011287462","host":"s3://npm-registry-packages"}},"0.2.3":{"name":"@adllang/jsonbinding","version":"0.2.3","license":"MIT","_id":"@adllang/jsonbinding@0.2.3","maintainers":[{"name":"timbod7","email":"tim@dockerz.net"}],"homepage":"https://github.com/adl-lang/ts-jsonbinding#readme","bugs":{"url":"https://github.com/adl-lang/ts-jsonbinding/issues"},"dist":{"shasum":"6f301946ca0b7c7364c333d0e00e64b75715de3f","tarball":"https://registry.npmjs.org/@adllang/jsonbinding/-/jsonbinding-0.2.3.tgz","fileCount":11,"integrity":"sha512-It03dmA1woSkLig34Ybv+RxDYU0QHCTBaQ3RWyceQGFBH1iwcjQ6PwD2mK0ZTkvtxdtw61tr6UEexQlUFA/wMA==","signatures":[{"sig":"MEYCIQDG6ObloRb0MdQVXRnGFOiW4WkOhsIWRnACEGjMzOyJigIhAJP+cM65UTi5sNY1hz0s6EpKuUyG7BmqBlOymq2Ty3Kn","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":54689},"main":"./script/jsonbinding.js","types":"./script/jsonbinding.d.ts","module":"./esm/jsonbinding.js","exports":{".":{"import":"./esm/jsonbinding.js","require":"./script/jsonbinding.js"}},"gitHead":"adae306dc49c02224e6958c54b3c14d5d86f8af9","scripts":{"test":"node test_runner.js"},"_npmUser":{"name":"timbod7","email":"tim@dockerz.net"},"repository":{"url":"git+https://github.com/adl-lang/ts-jsonbinding.git","type":"git"},"_npmVersion":"10.1.0","description":"A typescript library for JSON serialization","directories":{},"_nodeVersion":"20.7.0","_hasShrinkwrap":false,"devDependencies":{"picocolors":"^1.0.0","@types/node":"^20.9.0"},"_npmOperationalInternal":{"tmp":"tmp/jsonbinding_0.2.3_1731734662609_0.7774834154881873","host":"s3://npm-registry-packages"}},"0.2.5":{"name":"@adllang/jsonbinding","version":"0.2.5","license":"MIT","_id":"@adllang/jsonbinding@0.2.5","maintainers":[{"name":"timbod7","email":"tim@dockerz.net"}],"homepage":"https://github.com/adl-lang/ts-jsonbinding#readme","bugs":{"url":"https://github.com/adl-lang/ts-jsonbinding/issues"},"dist":{"shasum":"6215b313705baf402ab9a0baff18763b4b202a1a","tarball":"https://registry.npmjs.org/@adllang/jsonbinding/-/jsonbinding-0.2.5.tgz","fileCount":11,"integrity":"sha512-kb9a6l64N6bb77zWWqYS9DdjQ+E1aOPdi4HPLmkxglVNzssIYeipdxuXHAvDMEWH8c7onzwM1lyBWWJ2gLxJIA==","signatures":[{"sig":"MEQCIDHflNBWEyufw26ZQJO+JwR+MOQURx8zVeZ2HuAmQsLbAiBoJ3pIl1YYRscd908LxDhNbDvnv+rvtrrDYRwHCyUb+w==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":59651},"main":"./script/jsonbinding.js","types":"./script/jsonbinding.d.ts","module":"./esm/jsonbinding.js","exports":{".":{"import":"./esm/jsonbinding.js","require":"./script/jsonbinding.js"}},"gitHead":"7181ccbb3732282a67f35f33df7a49cb221dfca6","scripts":{"test":"node test_runner.js"},"_npmUser":{"name":"timbod7","email":"tim@dockerz.net"},"repository":{"url":"git+https://github.com/adl-lang/ts-jsonbinding.git","type":"git"},"_npmVersion":"11.4.2","description":"A typescript library for JSON serialization","directories":{},"_nodeVersion":"24.3.0","_hasShrinkwrap":false,"devDependencies":{"picocolors":"^1.0.0","@types/node":"^20.9.0"},"_npmOperationalInternal":{"tmp":"tmp/jsonbinding_0.2.5_1753254884511_0.06117008162771942","host":"s3://npm-registry-packages-npm-production"}},"0.3.0":{"name":"@adllang/jsonbinding","version":"0.3.0","license":"MIT","_id":"@adllang/jsonbinding@0.3.0","maintainers":[{"name":"timbod7","email":"tim@dockerz.net"}],"homepage":"https://github.com/adl-lang/ts-jsonbinding#readme","bugs":{"url":"https://github.com/adl-lang/ts-jsonbinding/issues"},"dist":{"shasum":"2b24080f550b9131b9cb0b547f3b5249f762a6f8","tarball":"https://registry.npmjs.org/@adllang/jsonbinding/-/jsonbinding-0.3.0.tgz","fileCount":11,"integrity":"sha512-Vi7cQWPhFaUg+H/Ycg8zb4n3m7PJHJx6mTKpbJGantmGCsw5v9JU63ugOjeAc+xk+Xrl+kOEE7xAYQ+JIuI/AA==","signatures":[{"sig":"MEUCIA8Pco+hYMVPY4PA+LpY0bJPM0l8fAc5uH0qLrHTN1N+AiEAhmvJFmNbxokIgPdakHN5jvuxE3YkC0y2gmUSpTY7lgI=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":63369},"main":"./script/jsonbinding.js","types":"./script/jsonbinding.d.ts","module":"./esm/jsonbinding.js","exports":{".":{"import":"./esm/jsonbinding.js","require":"./script/jsonbinding.js"}},"gitHead":"9f092bd2de4e01e765590fd4f38cf3fcfefe4df1","scripts":{"test":"node test_runner.js"},"_npmUser":{"name":"timbod7","email":"tim@dockerz.net"},"repository":{"url":"git+https://github.com/adl-lang/ts-jsonbinding.git","type":"git"},"_npmVersion":"10.8.2","description":"A typescript library for JSON serialization","directories":{},"_nodeVersion":"20.19.4","_hasShrinkwrap":false,"devDependencies":{"picocolors":"^1.0.0","@types/node":"^20.9.0"},"_npmOperationalInternal":{"tmp":"tmp/jsonbinding_0.3.0_1772673133282_0.9277168367630435","host":"s3://npm-registry-packages-npm-production"}},"0.4.0":{"name":"@adllang/jsonbinding","version":"0.4.0","description":"A typescript library for JSON serialization","repository":{"type":"git","url":"git+https://github.com/adl-lang/ts-jsonbinding.git"},"license":"MIT","bugs":{"url":"https://github.com/adl-lang/ts-jsonbinding/issues"},"main":"./script/jsonbinding.js","module":"./esm/jsonbinding.js","exports":{".":{"import":"./esm/jsonbinding.js","require":"./script/jsonbinding.js"}},"scripts":{"test":"node test_runner.js"},"devDependencies":{"@types/node":"^20.9.0","picocolors":"^1.0.0"},"_id":"@adllang/jsonbinding@0.4.0","gitHead":"a916c8b2ea82102f57563cb67076eaadf389f6f0","types":"./script/jsonbinding.d.ts","homepage":"https://github.com/adl-lang/ts-jsonbinding#readme","_nodeVersion":"20.19.4","_npmVersion":"10.8.2","dist":{"integrity":"sha512-X3vd8JeQAUfpqg1bOWMRDMGWWbdMTOPnAEhMTMyFExjKgEwKiJhcdt22HtEi+rd9aVfgZHd5WY80XglgN/RGeg==","shasum":"0cb154f9868b6f51be9eb7fb9b75907351f785b4","tarball":"https://registry.npmjs.org/@adllang/jsonbinding/-/jsonbinding-0.4.0.tgz","fileCount":11,"unpackedSize":66431,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQDi/tOmmhAPuYh2dwILLCZxSgXJNWjGHwAxg/AYmmXGswIhAM1U33iOIMDtg8FOfiEUkHFcm83KbhX5Bx1y9EDQsmml"}]},"_npmUser":{"name":"timbod7","email":"tim@dockerz.net"},"directories":{},"maintainers":[{"name":"timbod7","email":"tim@dockerz.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/jsonbinding_0.4.0_1783588818412_0.712748541865792"},"_hasShrinkwrap":false}},"time":{"created":"2024-07-15T04:53:37.872Z","modified":"2026-07-09T09:20:18.708Z","0.0.1":"2024-07-15T04:53:38.128Z","0.0.2":"2024-07-15T08:29:52.658Z","0.0.3":"2024-07-15T22:38:18.788Z","0.1.0":"2024-07-16T08:57:31.086Z","0.1.1":"2024-07-17T01:31:35.807Z","0.2.2":"2024-11-16T05:14:57.332Z","0.2.3":"2024-11-16T05:24:22.819Z","0.2.5":"2025-07-23T07:14:44.681Z","0.3.0":"2026-03-05T01:12:13.451Z","0.4.0":"2026-07-09T09:20:18.552Z"},"bugs":{"url":"https://github.com/adl-lang/ts-jsonbinding/issues"},"license":"MIT","homepage":"https://github.com/adl-lang/ts-jsonbinding#readme","repository":{"type":"git","url":"git+https://github.com/adl-lang/ts-jsonbinding.git"},"description":"A typescript library for JSON serialization","maintainers":[{"name":"timbod7","email":"tim@dockerz.net"}],"readme":"# A typescript library for JSON serialization\n\nKey features:\n\n- bidirectional (ie serialization and deserialization)\n- handles builtin types like `bigint`, `Date`, `Map<K,V>` and `Set<T>`\n- extensible\n- errors that describe the location of parse failures\n- support for unions, generics and custom types\n- typescript implementation\n\nHere's a brief [comparison with zod](#comparisons).\n\n## Overview\n\nThe core of the library is the type:\n\n```\ninterface JsonBinding<T> {\n  toJson(t: T): Json;\n  fromJson(json: Json): T;\n};\n```\n\nA `JsonBinding` of type `T` captures the ability to serialize a value of type\n`T` to JSON, and to deserialize a value of type `T` from JSON. `JsonBinding`s\ncan be easily constructed via library functions. For example\n\n```\nimport { JsonBinding } from \"@adllang/jsonbinding\";\nimport * as jb from '@adllang/jsonbinding';\n\ninterface User {\n  name: string,\n  birthday: Date,\n}\n\nconst JB_USER: JsonBinding<User> = jb.object({\n  name: jb.string(),\n  birthday: jb.date(),\n});\n```\n\nThen usage is:\n\n```\n> JB_USER.toJson({name: \"Robin\", birthday:new Date()})\n{\"birthday\": 1720998670768, \"name\": \"Robin\"}\n> JB_USER.fromJson({\"birthday\": 1720998670768, \"name\": \"Robin\"})\n{ \"birthday\": 2024-07-14T23:11:10.768Z, \"name\": \"Robin\"}\n> JB_USER.fromJson({\"name\": \"Robin\"})\nUncaughtError: expected an object with field birthday at $\n```\n\n## Inference\n\nIn the previous example, I like having the `User` interface explicit in the\ncode. But you can infer it from the JsonBinding, in the style of\n[zod](https://github.com/colinhacks/zod):\n\n```\nimport { JsonBinding } from \"@adllang/jsonbinding\";\nimport * as jb from '@adllang/jsonbinding';\n\nconst JB_USER = jb.object({\n  name: jb.string(),\n  birthday: jb.date(),\n});\n\ntype User = jb.Infer<typeof JB_USER>;\n```\n\n## Primitives\n\nThe following primitives are provided:\n\n```\nfunction string(): JsonBinding<string>;\nfunction number(): JsonBinding<number>;\nfunction boolean(): JsonBinding<boolean>;\nfunction nullv(): JsonBinding<null>;\nfunction json(): JsonBinding<Json>;\nfunction date(): JsonBinding<Date>;     # serialized as number of ms after unix epoch\nfunction bigint(): JsonBinding<bigint>; # serialized as a string to maintain precision\n```\n\nTechnically, `date()` and `bigint()` are implemented as mapped bindings (see\nbelow)\n\n## Objects\n\nThe libraries `object()` functions builds JSON bindings for typescript objects\nand interfaces. A simple example:\n\n```\ninterface User {\n  name: string,\n  birthday: Date,\n  roles: string[],\n}\n\nconst JB_USER: JsonBinding<User> = jb.object({\n  name: jb.string(),\n  birthday: jb.date(),\n  roles: jb.array(jb.string()),\n});\n```\n\nDefault values for fields can also be specified, and these will be used when\ndeserialising json streams that lack these fields. Hence, in this example:\n\n```\ninterface User {\n  name: string,\n  roles: string[],\n}\n\nconst JB_ROLE_ARRAY = jb.array(jb.string());\n\nconst JB_USER: JsonBinding<User> = jb.object({\n  name: jb.string(),\n  roles: jb.withDefault(JB_ROLE_ARRAY, []),\n});\n```\n\nthe roles field need not be present for successful deserialization:\n\n```\n> const u = JB_USER.fromJson({name:\"Fred\"});\n> u.name\n'Fred'\n> u.roles\n[]\n```\n\n## Discriminated Unions\n\nThe library has support for discriminated unions, using the `union()` function.\n\n```\ninterface Rectangle {\n  width: number,\n  height: number\n};\n\ninterface Circle {\n  radius: number;\n};\n\ntype Shape\n  = {kind: 'rectangle', value: Rectangle}\n  | {kind: 'circle', value: Circle};\n\n\nconst JB_RECTANGLE = jb.object({\n  width: jb.number(),\n  height: jb.number(),\n});\n\nconst JB_CIRCLE = jb.object({\n  radius : jb.number(),\n});\n\nconst JB_SHAPE: JsonBinding<Shape> = jb.union([\n  {kind: 'rectangle', value: JB_RECTANGLE},\n  {kind: 'circle', value: JB_CIRCLE},\n]);\n```\n\n## String enums\n\n```\nconst JB_FOOBAR: JsonBinding<'foo' | 'bar'> = jb.enum([\n  'foo',\n  'bar',\n]);\n```\n\n## Maps, Sets and Pairs\n\nare supported via the following functions:\n\n```\nfunction map<K, V>(jbk: JsonBinding<K>, jbv: JsonBinding<V>): JsonBinding<Map<K, V>>\nfunction set<T>(jbt: JsonBinding<T>): JsonBinding<Set<T>>\nfunction pair<A, B>(jba: JsonBinding<A>, jbb: JsonBinding<B>): JsonBinding<[A, B]>\n```\n\n## Mapped types\n\nMapped types in this library support conversions on serialization and\ndeserialization. One constructs a `JsonBinding` for a mapped type by providing a\n`JsonBinding` for the underlying type, and a pair of conversion functions to\nconvert the underlying type from/to the mapped type.\n\nThe serialisation of typescript `Date` objects is an example of this. We want\nthe in memory presentation to be a `Date` object, but we wish to serialize it as\nthe number of milliseconds since the epoch. This is written as:\n\n```\nconst JB_DATE: JsonBinding<Date> = jb.mapped(\n  jb.number(),                                  // serialize as a number\n  d => d.getTime(),                             // convert a Date to a number\n  n => new Date(n),                             // convert a number to a Date\n);\n```\n\nMapped types can also be used to create JsonBindings for typescript classes. For\nexample\n\n```\nclass Point2D {\n  constructor(readonly x: number, readonly y: number) {\n  }\n\n  add(offset: Point2D): Point2D {\n    return new Point2D(this.x + offset.x, this.y + offset.y);\n  }\n}\n\nconst JB_POINT_2D: JsonBinding<Point2D> = jb.mapped(\n  jb.object({x: jb.number(), y: jb.number()}),\n  p => p,\n  p => new Point2D(p.x, p.y)\n);\n```\n\n## Generic types\n\nA `JsonBinding` for a generic type can be constructed by writing a function to\nbuild the `JsonBinding` that takes as parameters the `JsonBinding`s of the\ngeneric type parameters. Referencing the Point2D example:\n\n```\ninterface Path<P> {\n  points: P[]\n};\n  \nfunction jbPath<P>(jbPoint: JsonBinding<P>): JsonBinding<Path<P>> {\n  return jb.object({\n    points: jb.array(jbPoint),\n  });\n}\n\nconst JB_PATH_2D: JsonBinding<Path<Point2D>> = jbPath(JB_POINT_2D);\n```\n\n## Recursive types\n\nA `lazy()` combinator is available to facilitate creating `JsonBinding`s for\nrecursive types.\n\n```\ninterface Category {\n  name: string,\n  subcategories: Category[]\n}\n\nfunction jbCategory(): JsonBinding<Category> {\n  return jb.object({\n    name: jb.string(),\n    subcategories: jb.array(jb.lazy(() => jbCategory())),\n  });\n}\n```\n\n## Other helpers\n\nThe library includes `JsonBinding` helpers\n\nfor string keyed maps:\n\n```\nexport type StringMap<T> = { [key: string]: T };\n\nexport function stringMap<T>(jbt: JsonBinding<T>): JsonBinding<StringMap<T>>;\n```\n\nfor values that may be null or some other type:\n\n```\nexport function orNull<T>(jbt: JsonBinding<T>): JsonBinding<T | null>;\n```\n\nfor values that may be undefined or some other type:\n\n```\nexport function orUndefined<T>(jbt: JsonBinding<T>): JsonBinding<T | undefined> {\n```\n\n# Comparisons\n\n## Zod\n\n[Zod](https://zod.dev/) deserves credit for introducing robust typescript\ndefined schema validations. It's widespread use reflects it's value. The\n`ts-jsonbinding` library was built primarily to address the following key\nlimitation of Zod:\n\n**zod is validation/deserialization only**. It can take accept external input,\nvalidate it, and then map it to internal typescript types. But it has no direct\nsupport for the opposite serialization path. As a concrete example zod has no\nequivalent for the `JB_USER.toJson` method [here](#overview)\n\nFor my needs writing data to JSON (ie serialisation) is just as important as\nvalidation and parsing (ie deserialization). `JSON.stringify()` only does the\nright thing for a small fraction of possible data types, and various other\nlibraries try and help with this (eg\n[superjson](https://github.com/flightcontrolhq/superjson)).\n\n`ts-jsonbinding` is a single library to deal with both serialization and\ndeserialization needs, with complete flexibility of the mapping between runtime\nvalues and their representation in JSON.\n\n# Development\n\nBuild and test:\n\n```\ndeno test\n```\n\nPublish to JSR:\n\n```\ndeno publish\n```\n\nPublish to NPM:\n\n```\ndeno task build_npm\ncd npm\nnpm login\nnpm publish\n```\n","readmeFilename":"README.md"}