{"id":17066292,"url":"https://github.com/kern/jason","last_synced_at":"2025-04-12T18:50:22.438Z","repository":{"id":56878364,"uuid":"1638012","full_name":"kern/jason","owner":"kern","description":"Insanely simple JSON templates","archived":false,"fork":false,"pushed_at":"2017-11-09T20:29:30.000Z","size":119,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-04-03T15:49:04.953Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/CapnKernul/jason","language":"Ruby","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/kern.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}},"created_at":"2011-04-19T22:51:47.000Z","updated_at":"2020-03-28T10:18:02.000Z","dependencies_parsed_at":"2022-08-20T11:40:30.547Z","dependency_job_id":null,"html_url":"https://github.com/kern/jason","commit_stats":null,"previous_names":["capnkernul/jason"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kern%2Fjason","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kern%2Fjason/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kern%2Fjason/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kern%2Fjason/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kern","download_url":"https://codeload.github.com/kern/jason/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618220,"owners_count":21134199,"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":[],"created_at":"2024-10-14T11:06:33.425Z","updated_at":"2025-04-12T18:50:22.411Z","avatar_url":"https://github.com/kern.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# jason - insanely simple JSON templates [![StillMaintained Status](http://stillmaintained.com/CapnKernul/jason.png)](http://stillmaintained.com/CapnKernul/jason) [![Build Status](http://travis-ci.org/CapnKernul/jason.png)](http://travis-ci.org/CapnKernul/jason) #\n\n## Problem ##\n\nThere's no easy way to create JSON templates in Ruby.\n\n## Solution ##\n\nUse Erubis to make the simplest thing that could possibly work.\n\n## Installation ##\n\n    gem install jason\n\n## Usage ##\n\nYou write jason templates in a fashion similar to regular old JSON with a\nnotable exception: trailing commas in arrays and objects are automatically\nremoved. This allows you to easily create JSON templates using iterators.\n\n    Jason.render('{ \"foo\": \"bar\" }') # =\u003e '{\"foo\":\"bar\"}'\n    \n    Jason.render(\u003c\u003c-EOS\n    {\n      \"test\": [\n        \u003c% if true %\u003e\n          \"foo\",\n        \u003c% end %\u003e\n        \"bar\", \u003c%# Notice how this trailing comma is perfectly valid. %\u003e\n      ]\n    }\n    EOS\n    ) # =\u003e '{\"test\":[\"foo\",\"bar\"]}'\n\nJason also redefines the `\u003c%= expr %\u003e` Erubis delimiter so that it converts the\nexpression to a JSON value by calling `#to_json` on the expression. If you'd\nlike to use regular interpolation, use the `\u003c%== expr %\u003e` delimiter instead.\n\n    Jason.render('\u003c%= 'test' %\u003e') # =\u003e '\"test\"'\n    Jason.render('\"\u003c%== 'test' %\u003e\"') # =\u003e '\"test\"'\n\nYou can configure the output format of the JSON:\n\n    Jason.output_format = :compact # This is the default.\n    Jason.output_format = :pretty\n\n`:compact` will remove any unnecessary whitespace in the JSON while `:pretty`\nwill indent the result JSON so that it looks, well, pretty.\n\nYou can add output listeners to jason so that you can run arbitrary code upon\nthe generated JSON. For example, if you'd like to log all of the JSON responses\nin Rails:\n\n    Jason.output_listeners \u003c\u003c lambda do |hash|\n      Rails.logger.info(\"[Jason] Generated output:\\n#{JSON.pretty_generate(hash)}\")\n    end\n    \n\n## Usage with Rails ##\n\nName your view template with the extension `jason`. Everything else is the same.\n\n    # in view_name.jason\n    {\n      \"foo\": \"bar\",\n      \"baz\": [\n        \u003c% unless @we_started_the_fire %\u003e\n          \"quz\",\n          \"quuz\",\n        \u003c% end %\u003e\n      ]\n    }\n    \n    # Renders: {\"foo\":\"bar\",\"baz\":[\"quz\",\"quuz\"]}\n\n## Note on Patches/Pull Requests ##\n\n* Fork the project.\n* Make your feature addition or bug fix.\n* Add tests for it. This is important so I don't break it in a future version unintentionally.\n* Commit, but do not mess with the `Rakefile`. If you want to have your own version, that is fine but bump the version in a commit by itself in another branch so I can ignore it when I pull.\n* Send me a pull request. Bonus points for git flow feature branches.\n\n## Resources ##\n\n* [GitHub Repository](https://github.com/CapnKernul/jason)\n* [Documentation](http://rubydoc.info/github/CapnKernul/jason)\n\n## License ##\n\nJason is licensed under the MIT License. See `LICENSE` for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkern%2Fjason","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkern%2Fjason","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkern%2Fjason/lists"}