{"id":23160613,"url":"https://github.com/disruptek/jason","last_synced_at":"2025-08-18T02:31:44.867Z","repository":{"id":54866185,"uuid":"269833218","full_name":"disruptek/jason","owner":"disruptek","description":"JSON done right 🤦","archived":false,"fork":false,"pushed_at":"2021-10-20T13:54:06.000Z","size":217,"stargazers_count":64,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T18:11:32.619Z","etag":null,"topics":["compile-time","encode","json","nim","serialization","serialize"],"latest_commit_sha":null,"homepage":"","language":"Nim","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/disruptek.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"disruptek"}},"created_at":"2020-06-06T01:42:51.000Z","updated_at":"2025-03-22T05:58:35.000Z","dependencies_parsed_at":"2022-08-14T05:10:26.793Z","dependency_job_id":null,"html_url":"https://github.com/disruptek/jason","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"purl":"pkg:github/disruptek/jason","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disruptek%2Fjason","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disruptek%2Fjason/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disruptek%2Fjason/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disruptek%2Fjason/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/disruptek","download_url":"https://codeload.github.com/disruptek/jason/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/disruptek%2Fjason/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270933640,"owners_count":24670459,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"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":["compile-time","encode","json","nim","serialization","serialize"],"created_at":"2024-12-17T23:11:30.265Z","updated_at":"2025-08-18T02:31:44.557Z","avatar_url":"https://github.com/disruptek.png","language":"Nim","funding_links":["https://github.com/sponsors/disruptek"],"categories":[],"sub_categories":[],"readme":"# jason\n\n[![Test Matrix](https://github.com/disruptek/jason/workflows/CI/badge.svg)](https://github.com/disruptek/jason/actions?query=workflow%3ACI)\n[![GitHub release (latest by date)](https://img.shields.io/github/v/release/disruptek/jason?style=flat)](https://github.com/disruptek/jason/releases/latest)\n![Minimum supported Nim version](https://img.shields.io/badge/nim-1.4.8%2B-informational?style=flat\u0026logo=nim)\n[![License](https://img.shields.io/github/license/disruptek/jason?style=flat)](#license)\n\n**mostly** compile-time JSON encoding\n\n\"I don't care.\" -- _Araq, 2020_\n\n## Why?\n\n- [This is the fastest known JSON serializer for Nim.](https://github.com/disruptek/jason#benchmarks)\n- It's pretty hard to misuse, but as simple as it is, it will get even better if a new concepts implementation lands in Nim.\n- It's not *fully* optimized yet; there's quite a bit more room to improve.\n- I *may* add a deserializer if a strong candidate doesn't materialize.  🤔\n\nAdvantages of `jason` over other serializers:\n\n1. encoding of tuples, objects, and iterators is \"free\" -- no loops to write\nand few-to-zero copies\n\n1. no runtime serialization exceptions and a distinct JSON type for safety\n\n1. easy custom serialization for your types, and even custom compile-time\nserialization\n\n## Usage\n\n```nim\n# an integer\necho 45.jason                  # 45\n\n# a float\necho jason(5.0)                # 5.0\n\n# a bool\necho jason true                # true\n\n# an enum (see below for custom serialization overriding)\necho Two.jason                 # 2\n\n# a string\necho jason\"foo\"                # \"foo\"\n\n# ref types are fine\necho jason((ref string) nil)   # null\n```\n\nTuples without named fields become JSON arrays.  Tuples with named fields\nbecome JSON objects.\n\n```nim\necho (1, 2, 3).jason                       # [1,2,3]\necho (cats: \"meow\", dogs: \"woof\").jason    # {\"cats\":\"meow\",\"dogs\":\"woof\"}\n```\n\nObjects are supported, with or without `ref` fields.\n\n```nim\ntype\n  O = object\n   cats: string\n   dogs: int\n   q: ref O\n\nlet o = O(cats: \"yuk\", dogs: 2)\necho o.jason   # {\"cats\":\"yuk\",\"dogs\":2,\"q\":null}\n```\n\nCustom serialization is trivial; just implement `jason` for your type.  No\nneed to guess as to whether you've implemented all necessary serializers;\nif it compiles, you're golden.\n\n```nim\ntype\n  B = object\n    x: int\n    y: string\n  C = seq[B]\n\nlet b = B(x: 3, y: \"sup\")\nlet c: C = @[ B(x: 1), B(x: 2), B(x: 3) ]\n\nconst a = B(x: 4, y: \"compile-time!\")\n\nfunc jason(n: B): Jason =\n  if n.x mod 2 == 0: jason\"even\"\n  else:              jason\"odd\"\n\n# enabling compile-time encoding is easy\nstaticJason C\n\n# or you can define static encoding yourself\nmacro jason(n: static[B]): Jason =\n  if n.x mod 2 == 0: jasonify\"1\"\n  else:              jasonify\"0\"\n\ncheck a.jason == \"1\"\ncheck b.jason == \"\"\"\"odd\"\"\"\"\ncheck c.jason == \"\"\"[\"odd\",\"even\",\"odd\"]\"\"\"\n```\n\n`Jason` is a proper type.\n\n```nim\nvar n: string = jason\"foo\"      # type error\nvar x: string = $\"foo\".jason    # ok\nvar y = jason\"foo\"              # ok\ny.add \"bif\"                     # type error\n```\n\n## Benchmarks\n\n### jason versus jsony\n\n[This is a comparison with the jsony\nlibrary.](https://github.com/disruptek/jason/blob/master/tests/sonny.nim)\n\n![jsony](docs/jsony.svg \"jsony\")\n\n### jason versus std/json\n\n[The source to the benchmark is found in the tests\ndirectory.](https://github.com/disruptek/jason/blob/master/tests/bench.nim)\n\n![bench](docs/bench.svg \"bench\")\n\n### jason versus packedjson\n\n[There is also a benchmark for the packedjson\nlibrary.](https://github.com/disruptek/jason/blob/master/tests/packed.nim)\n**Note:** The primary reason to choose `packedjson` is low memory overhead\nduring *deserialization*.\n\n![packedjson](docs/packed.svg \"packedjson\")\n\n### jason versus eminim\n\n[This is a comparison with the eminim\nlibrary.](https://github.com/disruptek/jason/blob/master/tests/emi.nim) As\n`eminim` serializes only to streams, we similarly issue a stream write in the\n`jason` benchmarks here, so that fair comparison may be made.\n\n![eminim](docs/eminim.svg \"eminim\")\n\n## Installation\n\n```\n$ nimph clone jason\n```\nor if you're still using Nimble like it's 2012,\n```\n$ nimble install https://github.com/disruptek/jason\n```\n\n## Documentation\n\nI'm going to try a little harder with these docs by using `runnableExamples`\nso the documentation demonstrates _current_ usage examples and working tests.\n\n[See the documentation for the jason module as generated directly from the\nsource.](https://disruptek.github.io/jason/jason.html)\n\n## License\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdisruptek%2Fjason","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdisruptek%2Fjason","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdisruptek%2Fjason/lists"}