{"id":15405196,"url":"https://github.com/fnando/json_blob","last_synced_at":"2026-04-28T10:36:08.683Z","repository":{"id":56879535,"uuid":"163341553","full_name":"fnando/json_blob","owner":"fnando","description":"Create `\u003cscript type=\"application/json;base64\"\u003e` tags to safely send data to the UI. You can then use https://github.com/fnando/json_blob-js to load this data on the client-side.","archived":false,"fork":false,"pushed_at":"2018-12-27T23:00:45.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-03-26T23:59:31.742Z","etag":null,"topics":["actionview","client-side","json","json-blob","server-side","template"],"latest_commit_sha":null,"homepage":"","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/fnando.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-27T22:32:26.000Z","updated_at":"2018-12-28T00:14:07.000Z","dependencies_parsed_at":"2022-08-20T23:40:12.316Z","dependency_job_id":null,"html_url":"https://github.com/fnando/json_blob","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/fnando/json_blob","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fjson_blob","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fjson_blob/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fjson_blob/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fjson_blob/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fnando","download_url":"https://codeload.github.com/fnando/json_blob/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fnando%2Fjson_blob/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32377587,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T09:24:15.638Z","status":"ssl_error","status_checked_at":"2026-04-28T09:24:15.071Z","response_time":56,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: 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":["actionview","client-side","json","json-blob","server-side","template"],"created_at":"2024-10-01T16:15:24.366Z","updated_at":"2026-04-28T10:36:08.661Z","avatar_url":"https://github.com/fnando.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# JSONBlob\n\n[![Travis-CI](https://travis-ci.org/fnando/json_blob.svg)](https://travis-ci.org/fnando/json_blob)\n[![Code Climate](https://codeclimate.com/github/fnando/json_blob/badges/gpa.svg)](https://codeclimate.com/github/fnando/json_blob)\n[![Test Coverage](https://codeclimate.com/github/fnando/json_blob/badges/coverage.svg)](https://codeclimate.com/github/fnando/json_blob/coverage)\n[![Gem](https://img.shields.io/gem/v/json_blob.svg)](https://rubygems.org/gems/json_blob)\n[![Gem](https://img.shields.io/gem/dt/json_blob.svg)](https://rubygems.org/gems/json_blob)\n\nCreate `\u003cscript type=\"application/json;base64\"\u003e` tags to safely send data to the UI. You can then use \u003chttps://github.com/fnando/json_blob-js\u003e to load this data on the client-side.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"json_blob\"\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install json_blob\n\n## Usage\n\nTo output data, use the `json_blob` method like the following:\n\n```erb\n\u003c%= json_blob :user, @user %\u003e\n```\n\nThis will output something like:\n\n```html\n\u003cscript data-name=\"user\" type=\"application/json;base64\"\u003eeyJuYW1lIjoiSm9obiBEb2UifQ==\u003c/script\u003e\n```\n\nOn the client-side you can load the data with something like the following. You're better off using \u003chttps://github.com/fnando/json_blob-js\u003e to avoid copying 'n' pasting code between projects.\n\n```js\nfunction loadJSONBlob(name, defaults = null) {\n  const element = document.querySelector(`script[type=\"application/json;base64\"][data-name=\"${name}\"]`);\n\n  if (!element) {\n    return defaults;\n  }\n\n  return JSON.parse(atob(element.innerHTML));\n}\n\nconst user = loadJSONBlob(\"user\");\n```\n\n### Ruby\n\nYou can use the methods to encode/decode payloads directly.\n\n```ruby\nencoded = JSONBlob.dump(a: 1)\ndecoded = JSONBlob.parse(encoded)\n```\n\nYou can also set your favorite JSON engine. The requirement is that it must implement the `dump(data)` and `parse(data)` methods.\n\n```ruby\nmodule CustomJSONEngine\n  def self.dump(data)\n    JSON.dump(data.merge(dump: true))\n  end\n\n  def self.parse(data)\n    JSON.parse(data).merge(parse: true)\n  end\nend\n\nJSONBlob.json_engine = CustomJSONEngine\n\nencoded = JSONBlob.dump(a: 1)\ndecoded = JSONBlob.parse(encoded)\n#=\u003e {\"a\" =\u003e 1, \"dump\": true, \"parse\": true}\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/fnando/json_blob. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the JSONBlob project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fnando/json_blob/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fjson_blob","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffnando%2Fjson_blob","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffnando%2Fjson_blob/lists"}