{"id":18448402,"url":"https://github.com/darkseal/dir2json","last_synced_at":"2025-04-08T01:32:15.145Z","repository":{"id":139348243,"uuid":"45945288","full_name":"Darkseal/dir2json","owner":"Darkseal","description":"A PHP CLI script to ouput the contents of a whole directory tree to a JSON object","archived":false,"fork":false,"pushed_at":"2015-11-11T01:09:41.000Z","size":0,"stargazers_count":12,"open_issues_count":0,"forks_count":6,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-23T03:51:15.146Z","etag":null,"topics":["cli","directory-tree","json","php","php-cli-script","php-page","php7"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Darkseal.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":"2015-11-10T22:45:30.000Z","updated_at":"2025-03-09T07:08:42.000Z","dependencies_parsed_at":"2023-03-13T17:22:47.402Z","dependency_job_id":null,"html_url":"https://github.com/Darkseal/dir2json","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Darkseal%2Fdir2json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Darkseal%2Fdir2json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Darkseal%2Fdir2json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Darkseal%2Fdir2json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Darkseal","download_url":"https://codeload.github.com/Darkseal/dir2json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247760496,"owners_count":20991501,"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":["cli","directory-tree","json","php","php-cli-script","php-page","php7"],"created_at":"2024-11-06T07:15:48.657Z","updated_at":"2025-04-08T01:32:14.889Z","avatar_url":"https://github.com/Darkseal.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# dir2json\nA PHP CLI script to ouput the contents of a whole directory tree to a JSON object.\n\n*by Ryan, 2015*  \nhttp://www.ryadel.com/\n* [Official Page](http://www.ryadel.com/en/portfolio/dir2json-en/)\n* [Documentation \u0026 info](http://www.ryadel.com/dir2json-a-php-cli-script-to-output-the-contents-of-a-folder-tree-into-a-json-object/)\n\n## What does it do\nIt fetches a directory tree structure like this:\n\n```\n/images/\n    /gif/\n        man.gif\n        woman.gif\n    /jpg/\n        photo1.jpg\n        photo2.jpg\n    /png/\n        avatar.png\n    howto.txt,\n    readme.md\n```\n\nand outputs its contents into a json-formatted file like this:\n\n```\n{\n    \"gif\": [\n      \"man.gif\",\n      \"woman.gif\"\n      ],\n    \"jpg\": [\n      \"photo1.jpg\",\n      \"photo2.jpg\"\n      ],\n    \"png\": [\n      \"avatar.png\"\n      ],\n    \"0\": \"howto.txt\",\n    \"1\": \"readme.md\"\n}\n```\n\nIt can be very useful when working with Javascript frameworks and/or similar scenarios where you need to load/browse/show a directory structure without being allowed to access the system IO.\n\n## Conversion rules\nThe json conversion is handled by the native php `json_encode` function (available in PHP 5 \u003e= 5.2.0, PECL json \u003e= 1.2.0, PHP 7). For further info on PHP's json_encode function, read here:\nhttp://php.net/manual/en/function.json-encode.php\n\nThe generated JSON object will adopt the following conventions:\n* If a folder contains only files (without subfolders), they will be listed as items of a single array.\n* If a folder contains one or more subfolders, each one will be listed as a key/value array.\n* If a folder contains files and subfolders, both will be listed as a key/value array: each file will have an auto-generated numeric key starting from 0 (numbers already used by a subfolder's name will be skipped).\n\n\n## Usage\nThe code it's meant to be used as a dedicated CLI script, but you can also execute it from a standard, web-hosted PHP page by populating the $argv[] array directly from code. If you need further help to implement it into a PHP page, contact me and I'll update the docs accordingly.\n\n### From CLI\n\n```\n \u003e php dir2json \u003ctargetFolder\u003e \u003coutputFile\u003e [JSON_OPTIONS]\n```\n\nJSON_OPTIONS is a bitmask consisting of:\n```\n  JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, \n  JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_PRESERVE_ZERO_FRACTION, \n  JSON_UNESCAPED_UNICODE, JSON_PARTIAL_OUTPUT_ON_ERROR\n```\n\nThe behaviour of these constants is described on the JSON constants page:\nhttp://php.net/manual/en/json.constants.php\n\n#### Example\n```\n \u003e php dir2json ./images out.json JSON_PRETTY_PRINT\n```\n\n## Useful Links\n* [dir2json project page on Ryadel.com](http://www.ryadel.com/dir2json-a-php-cli-script-to-output-the-contents-of-a-folder-tree-into-a-json-object/)\n* [dir2json article, explaining how it works](http://www.ryadel.com/en/portfolio/dir2json-en/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkseal%2Fdir2json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdarkseal%2Fdir2json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdarkseal%2Fdir2json/lists"}