{"id":26601463,"url":"https://github.com/gulpf/samson","last_synced_at":"2025-04-09T16:34:13.391Z","repository":{"id":87888522,"uuid":"172270122","full_name":"GULPF/samson","owner":"GULPF","description":"A JSON5 implementation for Nim.","archived":false,"fork":false,"pushed_at":"2020-04-28T18:54:26.000Z","size":110,"stargazers_count":20,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-23T18:50:56.240Z","etag":null,"topics":["json","json5","nim"],"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/GULPF.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}},"created_at":"2019-02-23T22:17:38.000Z","updated_at":"2024-09-12T13:19:45.000Z","dependencies_parsed_at":null,"dependency_job_id":"fafff5e7-d19f-471c-b5e5-b0825956d007","html_url":"https://github.com/GULPF/samson","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GULPF%2Fsamson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GULPF%2Fsamson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GULPF%2Fsamson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GULPF%2Fsamson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GULPF","download_url":"https://codeload.github.com/GULPF/samson/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248067805,"owners_count":21042359,"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","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":["json","json5","nim"],"created_at":"2025-03-23T18:40:06.875Z","updated_at":"2025-04-09T16:34:13.386Z","avatar_url":"https://github.com/GULPF.png","language":"Nim","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Samson\n\nSamson is a library for serializing and deserializing [JSON5](https://github.com/json5/json5), a superset of JSON. This library is still a work in progress and some features are missing.\n\n\u003c!--\n\n## Installation\n\nSamson is available on Nimble:\n```\nnimble install samson\n```\n--\u003e\n\n## Usage\n\nThe main API consists of only two procs: `toJson5` and `fromJson5`.\n\n### Simple example\n```nim\nimport samson\n\ntype User = object\n    name: string\n    age: range[0..high(int)]\n    timezone: Option[string]\n\nlet input = \"\"\"\n[\n    {\"name\": \"John Doe\", age: 25},\n    {\"name\": \"Jane Doe\", age: 22, timezone: \"Europe/Stockholm\"}\n]\n\"\"\"\n\nlet parsed = fromJson5(input, seq[User])\necho parsed\n# =\u003e @[(name: \"John Doe\", age: 25, timezone: None[string]), (name: \"Jane Doe\", age: 22, timezone: Some(\"Europe/Stockholm\"))]\necho toJson5(parsed)\n# =\u003e [{\"name\": \"John Doe\", age: 25, timezone: null}, {\"name\": \"Jane Doe\", age: 22, timezone: \"Europe/Stockholm\"}]\n```\n### Advanced example\nPragma annotations can be used to control how an object type is serialized and deserialized. These are defined and documented in the `samson / pragmas` module.\n\n```nim\nimport std/times, samson, samson/pragmas\n\ntype Advanced = object\n    nimField {.jsonFieldName: \"jsonField\".}: int\n    hidden {.jsonExclude.}: int\n    date {.jsonDateTimeFormat: \"yyyy-MM-dd\".}: DateTime\n\nlet x = Advanced(\n    nimField: 1,\n    hidden: 2,\n    date: initDateTime(1, mJan, 2010, 12, 00, 00, utc())\n)\necho toJson5(x)\n# =\u003e {\"jsonField\": 1, date: \"2010-01-01\"}\n```\n\n\u003c!--\n### JsonValue\n\nSometimes no proper JSON schema exists meaning that it's not possible to describe it with a normal object. For those cases, Samson offers a special `JsonValue` type. It can be used like any other supported type in Samson, e.g `fromJson5(input, JsonValue)`. The `JsonValue` type can represent any possible value in JSON. It should be avoided unless absolutely necessary, as it's a lot more convenient to use a proper type. Example:\n\n```nim\n\n```\n--\u003e\n\n### Supported types\n\nThe following types in the standard library have special support in Samson:\n\n\n- `int8`, `int16`, `int32`, `int`, and `int64`\n- `uint8`, `uint16`, and `uint32` (note: `uint` and `uint64` are not supported for now)\n- `float32` and `float64`\n- `string`\n- `char`\n- `enum`\n- `seq`\n- `array`\n- `bool`\n- `range` (with range checking)\n- `options.Option` (maps to `null` when empty)\n- `times.Time`\n- `times.DateTime`\n- `tables.Table` and `tables.OrderedTable` (maps to object)\n- `set`, `sets.HashSet`, and `sets.OrderedSet`\n\nSamson also supports custom `object` (mapped to objects in JSON5) and `tuple` (mapped to arrays in JSON5) types.\n\n## Generated docs\n\n- [samson module](https://gulpf.github.io/samson/samson.html)\n- [samson/errors module](https://gulpf.github.io/samson/errors.html)\n- [samson/pragmas module](https://gulpf.github.io/samson/pragmas.html)\n\n## Planned features\n\n- Stream based API.\n- Support for type variants.\n- Support for pretty printing.\n- Support for dynamic JSON.\n- A strict JSON mode which doesn't support JSON5 features.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgulpf%2Fsamson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgulpf%2Fsamson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgulpf%2Fsamson/lists"}