{"id":17681219,"url":"https://github.com/z64/api_mapper","last_synced_at":"2026-04-30T01:39:10.116Z","repository":{"id":80745999,"uuid":"139533393","full_name":"z64/api_mapper","owner":"z64","description":"Generate Crystal structs from JSON API responses","archived":false,"fork":false,"pushed_at":"2018-07-03T06:50:10.000Z","size":10,"stargazers_count":2,"open_issues_count":2,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-30T19:14:18.892Z","etag":null,"topics":["api","crystal","json"],"latest_commit_sha":null,"homepage":null,"language":"Crystal","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/z64.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":"2018-07-03T05:37:06.000Z","updated_at":"2023-02-18T03:40:06.000Z","dependencies_parsed_at":"2023-03-12T12:05:52.639Z","dependency_job_id":null,"html_url":"https://github.com/z64/api_mapper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/z64/api_mapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z64%2Fapi_mapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z64%2Fapi_mapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z64%2Fapi_mapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z64%2Fapi_mapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/z64","download_url":"https://codeload.github.com/z64/api_mapper/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/z64%2Fapi_mapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32451481,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-29T22:27:22.272Z","status":"ssl_error","status_checked_at":"2026-04-29T22:10:49.234Z","response_time":110,"last_error":"SSL_read: 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":["api","crystal","json"],"created_at":"2024-10-24T09:10:33.889Z","updated_at":"2026-04-30T01:39:10.084Z","avatar_url":"https://github.com/z64.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# api_mapper\n\nThis is a proof of concept shard for developing object mappings for JSON APIs\nin an automated fashion.\n\nThe idea is to use a pull parser to interpret the API response into an ECR\ntemplate that generates a struct mapped with `JSON::Serializable`.\n\n## Usage\n\nAt the moment, something like this should work:\n\n```crystal\nrequire \"api_mapper\"\n\nclass_name = ARGV[0]\nfilename = ARGV[1]?\n\nio = if filename\n       File.open(filename, \"w\")\n     else\n       STDOUT\n     end\n\ntemplate = APIMapper::ObjectTemplate.from_json(STDIN, class_name)\ntemplate.to_s(io)\n\nio.close if io.is_a?(File)\n```\n\nLet's try [httpbin.org's GET](https://httpbin.org/#/HTTP_Methods/get_get):\n\n```\ncurl \\\n  -X GET \"https://httpbin.org/get?foo=bar\" \\\n  -H \"accept: application/json\"\\\n  | ./test Response\n```\n\nWe'll get on STDOUT:\n\n```crystal\nstruct Response\n  include JSON::Serializable\n\n  @[JSON::Field(key: \"args\")]\n  property args : T # =\u003e {\"foo\":\"bar\"}\n\n  @[JSON::Field(key: \"headers\")]\n  property headers : T # =\u003e {\"Accept\":\"application/json\",\"Connection\":\"close\",\"Host\":\"httpbin.org\",\"User-Agent\":\"curl/7.60.0\"}\n\n  @[JSON::Field(key: \"origin\")]\n  property origin : String # =\u003e \"12.34.456.789\"\n\n  @[JSON::Field(key: \"url\")]\n  property url : String # =\u003e \"https://httpbin.org/get?foo=bar\"\nend\n```\n\n- See [other examples](https://gist.github.com/z64/cdde1e054f83046b2dc67f24daea2030) from [Discord's API](https://discordapp.com/developers/docs/intro)\n\n- The raw value of that key is written in a comment following the property, so\n  that you can review it afterwards and maybe change it to a more accurate type.\n\n- A `JSON::Field` annotation is provided with `key`, as the most common\n  correction from an API response you might make for use in Crystal-space is\n  giving the property a more appropriate name. The line can be left, or removed\n  if you don't need it.\n\n## Status\n\nThere's lots of things this doesn't support yet, but it shows its possible and\nprobably very useful in getting a head start in mapping very large API responses.\n\n- More JSON types should be covered\n- For `:begin_object`, we could parse this again into *another* `ObjectTemplate`\n  and defer its output to output a full mapping for a nested object.\n\nIf this is useful to you, please feel free to PR! This was just an experiment\nand I may or may not keep developing it in my free time.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz64%2Fapi_mapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fz64%2Fapi_mapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fz64%2Fapi_mapper/lists"}