{"id":15028967,"url":"https://github.com/alrik11es/object-dot-notation","last_synced_at":"2025-04-09T20:32:22.380Z","repository":{"id":56946314,"uuid":"93510313","full_name":"alrik11es/object-dot-notation","owner":"alrik11es","description":"Object dot notation getter","archived":false,"fork":false,"pushed_at":"2019-02-21T15:05:31.000Z","size":86,"stargazers_count":4,"open_issues_count":3,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T22:25:23.079Z","etag":null,"topics":["composer","dot","dot-notation","laravel","notation","object","php5","symfony"],"latest_commit_sha":null,"homepage":"","language":"PHP","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/alrik11es.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":"2017-06-06T11:22:28.000Z","updated_at":"2021-04-13T10:08:24.000Z","dependencies_parsed_at":"2022-08-21T02:40:31.131Z","dependency_job_id":null,"html_url":"https://github.com/alrik11es/object-dot-notation","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik11es%2Fobject-dot-notation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik11es%2Fobject-dot-notation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik11es%2Fobject-dot-notation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alrik11es%2Fobject-dot-notation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alrik11es","download_url":"https://codeload.github.com/alrik11es/object-dot-notation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248107338,"owners_count":21048905,"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":["composer","dot","dot-notation","laravel","notation","object","php5","symfony"],"created_at":"2024-09-24T20:09:27.059Z","updated_at":"2025-04-09T20:32:22.356Z","avatar_url":"https://github.com/alrik11es.png","language":"PHP","readme":"![alt tag](https://raw.githubusercontent.com/alrik11es/object-dot-notation/master/dot-library.png) [![Build Status](https://travis-ci.org/alrik11es/object-dot-notation.svg?branch=master)](https://travis-ci.org/alrik11es/object-dot-notation)\n\n    The idea behind this library is to allow the access through\n    `config.port` dot notation to object data.\n\n### Why?\nMy main problem was when accessing API data.\n```json\n{\n    \"hits\":{\n        \"products\": [\n            {\n                \"name\": \"Shoe\"\n            }\n        ]\n    }\n}\n```\nImagine this is the result from an API. Usually to be sure that the data is what I want I'm gonna need to do:\n```php\n\u003c?php\n$result = r(); // imagine this is the result from an API with the json message abobe\nif(is_object($result) \u0026\u0026 property_exists($result, 'hits')){\n    if(is_object($result-\u003ehits) \u0026\u0026 property_exists($result-\u003ehits, 'products')){\n        $whatiwant = $result-\u003ehits-\u003eproducts;\n    }\n}\n```\nThis is really time consuming. I just needed a way to do something like:\n```php\n\u003c?php\n$d = \\Alr\\ObjectDotNotation\\Data::load(r());\n$whatiwant = $d-\u003eget('hits.products');\n```\n**Note:** In PHP7 you can just use  `$var = $something ?? $something2;` but if you need to do this dynamically it becomes harder to do.\n\n## Demo\n\n[You can try a demo here](http://demo.dotnotation.net)\n\n## Installation\n\nRequires composer and PHP5.6+\n\n\u003e $ composer require alrik11es/object-dot-notation\n\n## Usage\n\nWhen the property is not found a `null` will be returned.\n\nTake this object as example:\n```json\n{\n    \"config\": {\n        \"port\": \"1234\",\n        \"url\": \"testurl.com\"\n    }\n}\n```\nThen:\n```php\n\u003c?php\n$d = \\Alr\\ObjectDotNotation\\Data::load($mixed);\necho $d-\u003eget('config.port'); // 1234\necho $d-\u003e{'config.port'};\necho $d-\u003econfig; // ['port'=\u003e1234 ...]\n```\n### Array and array search\n\nFor other kind of uses you're gonna need to get a position of an array or search\nand get the first value of array.\n\nTake this object as example:\n```json\n{\n    \"config\": [{\n        \"port\": \"80\",\n        \"url\": \"aurl.com\"\n    },{\n        \"port\": \"90\",\n        \"url\": \"burl.com\"\n    }]\n}\n```\nYou can use this way to access the information:\n```php\n\u003c?php\n$d = \\Alr\\ObjectDotNotation\\Data::load($mixed);\necho $d-\u003eget('config[0].port'); // 80\necho $d-\u003e{'config[port=90|first].url'}; // burl.com\n```\n\n### Filters\nYou can use filters for the array selection process.\n\n`[port=90|first]`\n\n\u003e IMPORTANT NOTE: Actually you can only use `|first` filter, use it always because it's going to be needed on future versions to avoid compatibility problems.\n\n#### Advanced filters\n***TODO***\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falrik11es%2Fobject-dot-notation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falrik11es%2Fobject-dot-notation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falrik11es%2Fobject-dot-notation/lists"}