{"id":18623555,"url":"https://github.com/codica2/administrate-field-jsonb","last_synced_at":"2025-04-12T22:39:14.978Z","repository":{"id":44944267,"uuid":"211342673","full_name":"codica2/administrate-field-jsonb","owner":"codica2","description":"A plugin to show and edit JSON objects within Administrate.","archived":false,"fork":false,"pushed_at":"2024-12-16T12:38:37.000Z","size":573,"stargazers_count":47,"open_issues_count":13,"forks_count":18,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-04T02:08:55.364Z","etag":null,"topics":["administrate","adminpanel","field","jsonb"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/codica2.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-27T14:54:32.000Z","updated_at":"2024-12-16T13:43:31.000Z","dependencies_parsed_at":"2024-06-20T21:58:02.103Z","dependency_job_id":"08ed8edb-890a-49a3-9a83-be907665c630","html_url":"https://github.com/codica2/administrate-field-jsonb","commit_stats":{"total_commits":23,"total_committers":7,"mean_commits":"3.2857142857142856","dds":0.4782608695652174,"last_synced_commit":"5cbe658b271e3666df984bbcabf39e8345270185"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fadministrate-field-jsonb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fadministrate-field-jsonb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fadministrate-field-jsonb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codica2%2Fadministrate-field-jsonb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codica2","download_url":"https://codeload.github.com/codica2/administrate-field-jsonb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248643043,"owners_count":21138353,"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":["administrate","adminpanel","field","jsonb"],"created_at":"2024-11-07T04:24:59.522Z","updated_at":"2025-04-12T22:39:14.946Z","avatar_url":"https://github.com/codica2.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Administrate::Field::Jsonb\n\nA plugin to show and edit JSON objects within [Administrate](https://github.com/thoughtbot/administrate). inspired by [Administrate::Field::JSON](https://github.com/eddietejeda/administrate-field-json).\n\nThis gem uses [jsoneditor](https://github.com/josdejong/jsoneditor).\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'administrate-field-jsonb'\n```\n\nAnd then execute:\n\n```bash\nbundle\n```\n\nIf you are using asset pipeline, add the following lines to your `manifest.js`:\n\n```js\n//= link administrate-field-jsonb/application.css\n//= link administrate-field-jsonb/application.js\n```\n\nThe manifest file is at `app/assets/config` by default.\n\n## Usage\n\n```ruby\nATTRIBUTE_TYPES = {\n  # ...\n  details: Field::JSONB\n}.freeze\n```\n\nIf you have some kind of serialization, you can call methods on your object with `transform` option.\n\n```ruby\nATTRIBUTE_TYPES = {\n  # ...\n  details: Field::JSONB.with_options(\n    transform: %w[to_h symbolize_keys]\n  )\n}.freeze\n```\n\nIt also supports Proc.\n\n```ruby\nATTRIBUTE_TYPES = {\n  # ...\n  details: Field::JSONB.with_options(\n    transform: [:transformation, Proc.new { |item| item.merge({ foo: 'bar' }) }]\n  )\n}.freeze\n```\n\nAnd there is a built in `parse_json` option, it will call `JSON.parse(your_object)` on your object.\n\n```ruby\nATTRIBUTE_TYPES = {\n  # ...\n  details: Field::JSONB.with_options(\n    transform: [:parse_json, :some_other_stuff]\n  )\n}.freeze\n```\n\nIf you want to edit json displaying on `show` page, you can use `advanced_view` option (both JSON and arrays are supported).\n\n```ruby\nATTRIBUTE_TYPES = {\n  # ...\n  details: Field::JSONB.with_options(transform: %i[to_h symbolize_keys], advanced_view: {\n    company:  Field::String,\n    position: Field::String,\n    skills: Field::JSONB.with_options(advanced_view: {\n      'name'  =\u003e Field::String,\n      'years' =\u003e Field::Number.with_options(suffix: ' years')\n    })\n  }),\n  languages: Field::JSONB.with_options(advanced_view: {\n    'title' =\u003e Field::String,\n    'code'  =\u003e Field::String,\n  })\n}.freeze\n```\n\nNOTE: don't define `advanced_view` option if you want to display JSON with the [jsoneditor](https://github.com/josdejong/jsoneditor).\n\nTo customize what to display if you have an empty value, use `blank_sign` option, by default it's `-`.\n\n```ruby\nATTRIBUTE_TYPES = {\n  # ...\n  details: Field::JSONB.with_options(\n    blank_sign: 'oops, missed'\n  )\n}.freeze\n```\n\nIn some situations you may preffer not to nullify empty records. For example you store your JSONB in `not null` database column and always have at least an empty json object `{}`. In such situation you can use `nil_blank` option:\n\n```ruby\nATTRIBUTE_TYPES = {\n  # ...\n  details: Field::JSONB.with_options(\n    nil_blank: false\n  )\n}.freeze\n```\n\n## How it looks like\n\n### Form\n\n\u003cp align=\"center\"\u003e\n \u003cimg src=\"docs/images/form.png\"\u003e\n\u003c/p\u003e\n\n### Show\n\n#### jsoneditor mode\n\n\u003cp align=\"center\"\u003e\n \u003cimg src=\"docs/images/show_jsoneditor.png\"\u003e\n\u003c/p\u003e\n\n#### advanced_view mode\n\n\u003cp align=\"center\"\u003e\n \u003cimg src=\"docs/images/advanced_view_full.png\"\u003e\n\u003c/p\u003e\n\n#### advanced_view object\n\n\u003cp align=\"center\"\u003e\n \u003cimg src=\"docs/images/advanced_view_object.png\"\u003e\n\u003c/p\u003e\n\n#### advanced_view array\n\n\u003cp align=\"center\"\u003e\n \u003cimg src=\"docs/images/advanced_view_array.png\"\u003e\n\u003c/p\u003e\n\n## Recipes\n\nIf you want to store your JSON in hash format and not a string add this to your model.\n\n```ruby\ndef your_field_name=(value)\n  self[:your_field_name] = value.is_a?(String) ? JSON.parse(value) : value\nend\n```\n\nExample:\n\n```ruby\ndef details=(value)\n  self[:details] = value.is_a?(String) ? JSON.parse(value) : value\nend\n```\n\n\u003chr\u003e\n\nIf you don't see details in `advanced_view`, try to add this\n\n```ruby\ntransform: %i[to_h symbolize_keys]\n```\n\nor use string keys.\n\n```ruby\nlanguages: Field::JSONB.with_options(advanced_view: {\n  'title' =\u003e Field::String,\n  'code'  =\u003e Field::String,\n})\n```\n\n## License\n\nCopyright © 2015-2025 Codica. It is released under the [MIT License](https://opensource.org/licenses/MIT).\n\n## About Codica\n\n[![Codica logo](https://www.codica.com/assets/images/logo/logo.svg)](https://www.codica.com)\n\nAdministrate::Field::Jsonb is maintained by Codica. The names and logos for Codica are trademarks of Codica.\n\nWe love open source software! See [our other projects](https://github.com/codica2) or [hire us](https://www.codica.com/) to design, develop, and grow your product.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodica2%2Fadministrate-field-jsonb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodica2%2Fadministrate-field-jsonb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodica2%2Fadministrate-field-jsonb/lists"}