{"action":"created","issue":{"url":"https://api.github.com/repos/koorchik/LIVR/issues/56","repository_url":"https://api.github.com/repos/koorchik/LIVR","labels_url":"https://api.github.com/repos/koorchik/LIVR/issues/56/labels{/name}","comments_url":"https://api.github.com/repos/koorchik/LIVR/issues/56/comments","events_url":"https://api.github.com/repos/koorchik/LIVR/issues/56/events","html_url":"https://github.com/koorchik/LIVR/issues/56","id":310366965,"number":56,"title":"Validate keys in objects","user":{"login":"chtseac","id":13946731,"avatar_url":"https://avatars3.githubusercontent.com/u/13946731?v=4","gravatar_id":"","url":"https://api.github.com/users/chtseac","html_url":"https://github.com/chtseac","followers_url":"https://api.github.com/users/chtseac/followers","following_url":"https://api.github.com/users/chtseac/following{/other_user}","gists_url":"https://api.github.com/users/chtseac/gists{/gist_id}","starred_url":"https://api.github.com/users/chtseac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chtseac/subscriptions","organizations_url":"https://api.github.com/users/chtseac/orgs","repos_url":"https://api.github.com/users/chtseac/repos","events_url":"https://api.github.com/users/chtseac/events{/privacy}","received_events_url":"https://api.github.com/users/chtseac/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-02T00:34:07Z","updated_at":"2018-04-06T07:35:51Z","closed_at":null,"author_association":"NONE","body":"Is there a way to validate keys in an object?\r\n\r\nTo put it into a theorycraft example, something like this, borrowing `to_entries` and `from_entries` from [jq's filters of the same name](https://stedolan.github.io/jq/manual/v1.5/#to_entries,from_entries,with_entries):\r\n\r\nRule:\r\n\r\n```\r\n{\r\n  author: ['required', 'string'],\r\n  commits: ['to_entries', {\r\n    'nested_object': {\r\n      'key': ['required', {'like': '^[0-9a-f]+$'}],\r\n      'value': ['required', 'string']\r\n    }\r\n  }, 'from_entries']\r\n}\r\n```\r\n\r\nValid data:\r\n\r\n```\r\n{\r\n  author: 'chtseac',\r\n  commits: {\r\n    '6d12ba9': 'Add foo to bar',\r\n    'e32d134': 'Initial commit'\r\n  }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/koorchik/LIVR/issues/comments/379173239","html_url":"https://github.com/koorchik/LIVR/issues/56#issuecomment-379173239","issue_url":"https://api.github.com/repos/koorchik/LIVR/issues/56","id":379173239,"user":{"login":"koorchik","id":189374,"avatar_url":"https://avatars3.githubusercontent.com/u/189374?v=4","gravatar_id":"","url":"https://api.github.com/users/koorchik","html_url":"https://github.com/koorchik","followers_url":"https://api.github.com/users/koorchik/followers","following_url":"https://api.github.com/users/koorchik/following{/other_user}","gists_url":"https://api.github.com/users/koorchik/gists{/gist_id}","starred_url":"https://api.github.com/users/koorchik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/koorchik/subscriptions","organizations_url":"https://api.github.com/users/koorchik/orgs","repos_url":"https://api.github.com/users/koorchik/repos","events_url":"https://api.github.com/users/koorchik/events{/privacy}","received_events_url":"https://api.github.com/users/koorchik/received_events","type":"User","site_admin":false},"created_at":"2018-04-06T07:35:51Z","updated_at":"2018-04-06T07:35:51Z","author_association":"OWNER","body":"Looking at your use case, I believe that there can be 3 possible options:\r\n1. You can register several universal rules (like \"object_keys\", \"object_values\") for  validation.\r\n\r\n```\r\n{\r\n  author: ['required', 'string'],\r\n  commits: [\r\n     'required',\r\n     {'object_keys': [{ like: '^[0-9a-f]+$' }]\r\n     {'object_values': ['required', {max_length: 10}]\r\n   ], \r\n}\r\n```\r\n2. You can register a use case specific rule like 'commits_objects' or 'commits'\r\nSo, it will be \r\n```\r\n{\r\n  author: ['required', 'string'],\r\n  commits: ['required', 'commits']\r\n}\r\n```\r\n3. Change data format to commits: ```[ {hash: '6d12ba9', message: 'Add foo to bar', date: ...}, ...]```. "}}
{"actor":{"display_login":"koorchik"}}