{"id":14966546,"url":"https://github.com/eluhr/yii2-json-attribute-behavior","last_synced_at":"2025-09-23T07:31:52.045Z","repository":{"id":213702349,"uuid":"734745563","full_name":"eluhr/yii2-json-attribute-behavior","owner":"eluhr","description":"Automatically convert values to array before validation","archived":false,"fork":false,"pushed_at":"2024-01-01T00:37:50.000Z","size":16,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-25T22:26:17.770Z","etag":null,"topics":["behavior","json","yii2"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eluhr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2023-12-22T13:54:22.000Z","updated_at":"2023-12-29T21:56:53.000Z","dependencies_parsed_at":"2023-12-28T15:47:17.936Z","dependency_job_id":null,"html_url":"https://github.com/eluhr/yii2-json-attribute-behavior","commit_stats":null,"previous_names":["eluhr/yii2-json-attribute-behavior"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/eluhr/yii2-json-attribute-behavior","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eluhr%2Fyii2-json-attribute-behavior","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eluhr%2Fyii2-json-attribute-behavior/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eluhr%2Fyii2-json-attribute-behavior/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eluhr%2Fyii2-json-attribute-behavior/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eluhr","download_url":"https://codeload.github.com/eluhr/yii2-json-attribute-behavior/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eluhr%2Fyii2-json-attribute-behavior/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":276537911,"owners_count":25659929,"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","status":"online","status_checked_at":"2025-09-23T02:00:09.130Z","response_time":73,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["behavior","json","yii2"],"created_at":"2024-09-24T13:36:34.422Z","updated_at":"2025-09-23T07:31:51.747Z","avatar_url":"https://github.com/eluhr.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Yii2 JSON Attribute Behavior\n============================\nThis behavior automatically decodes attributes from JSON to arrays before validation, handling errors and re-encoding if validation fails.\nWith this a \"real\" json string can be further processed.\n\n![CI Workflow](https://github.com/eluhr/yii2-json-attribute-behavior/actions/workflows/ci.yml/badge.svg)\n\nInstallation\n------------\n\nThe preferred way to install this extension is through [composer](https://getcomposer.org/download/).\n\nEither run\n\n```\ncomposer require --prefer-dist eluhr/yii2-json-attribute-behavior \"*\"\n```\n\nor add\n\n```\n\"eluhr/yii2-json-attribute-behavior\": \"*\"\n```\n\nto the `require` section of your `composer.json` file.\n\nUsage\n-----\n\nIn a `yii\\base\\Model` or a derivation thereof, the behavior can be used as follows:\n\n```php\npublic function behaviors(): array\n{\n    $behaviors = parent::behaviors();\n    $behaviors['json-attribute'] = [\n        'class' =\u003e eluhr\\jsonAttributeBehavior\\JsonAttributeBehavior::class,\n        'attributes' =\u003e [\n            'data_json'\n        ]\n    ];\n    return $behaviors;\n}\n```\n\nBy using this behavior it does not matter if the attribute is a string or an array. \nThe behavior will always ensure, that the attribute is an array before saving the data to the database and yii will handle the rest.\n\nThis behavior supports [i18n](https://www.yiiframework.com/doc/guide/2.0/en/tutorial-i18n). By adding the `json-attribute-behavior` category in your config you can overwrite the default error messages.\n\nTesting\n-------\n\nAfter installing dependencies via composer you can run the tests with:\n\n```bash\nmake test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feluhr%2Fyii2-json-attribute-behavior","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feluhr%2Fyii2-json-attribute-behavior","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feluhr%2Fyii2-json-attribute-behavior/lists"}