{"id":22533429,"url":"https://github.com/oknoorap/jsonar","last_synced_at":"2025-04-09T18:04:24.067Z","repository":{"id":48000409,"uuid":"91547122","full_name":"oknoorap/jsonar","owner":"oknoorap","description":":sunny: Convert JSON to PHP native Array.","archived":false,"fork":false,"pushed_at":"2022-12-06T21:36:40.000Z","size":150,"stargazers_count":7,"open_issues_count":14,"forks_count":3,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-03-23T20:03:07.614Z","etag":null,"topics":["json","php","php-array"],"latest_commit_sha":null,"homepage":null,"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/oknoorap.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-05-17T07:35:04.000Z","updated_at":"2023-03-10T07:10:46.000Z","dependencies_parsed_at":"2023-01-23T15:16:48.035Z","dependency_job_id":null,"html_url":"https://github.com/oknoorap/jsonar","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oknoorap%2Fjsonar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oknoorap%2Fjsonar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oknoorap%2Fjsonar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oknoorap%2Fjsonar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oknoorap","download_url":"https://codeload.github.com/oknoorap/jsonar/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248084170,"owners_count":21045123,"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":["json","php","php-array"],"created_at":"2024-12-07T09:08:17.917Z","updated_at":"2025-04-09T18:04:24.045Z","avatar_url":"https://github.com/oknoorap.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# :sunny: JSONAR\nConvert JSON or javascript object to PHP native Array.\n\n## Install\nUsing NPM  \n`npm install jsonar --save`\n\nUsing Yarn  \n`yarn add jsonar`\n\n## Usage\n```javascript\nconst fs = require('fs')\nconst path = require('path')\nconst jsonar = require('jsonar')\nconst jsonStr = fs.readFileSync(path.join(__dirname, 'test.json'), 'ascii')\nconst world = 'World'\n\nconsole.log(jsonStr)\n/**\n* Example of json file\n\n{\n  \"greetings\": \"Hello\",\n  \"answers\": 42,\n  \"slug\": jsonar.literal(`slugify_fn(\"Hello ${world}\")`),\n  \"inception\": {\n    \"nested\": {\n      \"object\": true\n    },\n    \"array\": [\n      \"string\",\n      true,\n      100,\n      {\n        \"inception\": true\n      }\n    ]\n  },\n  \"playlist\": [\n    {\n      \"id\": \"DHyUYg8X31c\",\n      \"desc\": \"Do Robots Deserve Rights? What if Machines Become Conscious?\"\n    },\n    {\n      \"id\": \"ijFm6DxNVyI\",\n      \"desc\": \"The Most Efficient Way to Destroy the Universe - False Vacuum\"\n    }\n  ]\n}\n*/\n\nconst phpArray = jsonar.arrify(jsonStr, {prettify: true})\n```\n\nPHP Array Output  \n```php\narray(\n        \"greetings\" =\u003e \"Hello\",\n        \"answers\" =\u003e 42,\n        \"slug\" =\u003e slug_fn(\"Hello World\"),\n        \"inception\" =\u003e array(\n                \"nested\" =\u003e array(\n                        \"object\" =\u003e true\n                ),\n                \"array\" =\u003e array(\n                        \"string\",\n                        true,\n                        100,\n                        array(\n                                \"inception\" =\u003e true\n                        )\n                )\n        ),\n        \"playlist\" =\u003e array(\n                array(\n                        \"id\" =\u003e \"DHyUYg8X31c\",\n                        \"desc\" =\u003e \"Do Robots Deserve Rights? What if Machines Become Conscious?\"\n                ),\n                array(\n                        \"id\" =\u003e \"ijFm6DxNVyI\",\n                        \"desc\" =\u003e \"The Most Efficient Way to Destroy the Universe - False Vacuum\"\n                )\n        )\n);\n```\n\n```javascript\n// Convert array to json again\njsonar.parse(`your php array string here`)\n```\n\n### Methods\n#### `jsonar.arrify(json: Object | String, options: Object)`\n\n| Arguments | Description |\n| --- | --- |\n| **json** | JSON string or Javascript Object. |\n| **options** | Default options are: `{ prettify: false, indent: 1, space: false, quote: jsonar.quoteTypes.DOUBLE }` |\n\n#### `jsonar.parse(phpString: String, options: Boolean)`\n\n| Arguments | Description |\n| --- | --- |\n| **phpString** | PHP String. |\n| **options** | Default options are: `{ asObject: true, emptyRules: {} }`, `emptyRules` should be objects that has the same structure with your object, if you don't set `emptyRules` all empty objects will be converted as primitive array `[]`, because PHP AST read an empty object as array |\n\n#### `jsonar.literal(string)`\n\n### Constants\n`jsonar.quoteTypes.SINGLE = '`  \n`jsonar.quoteTypes.DOUBLE = \"`\n\n## License\nMIT © [oknoorap](https://github.com/oknoorap)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foknoorap%2Fjsonar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foknoorap%2Fjsonar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foknoorap%2Fjsonar/lists"}