{"id":13912655,"url":"https://github.com/hjson/hjson-php","last_synced_at":"2025-04-06T03:08:21.361Z","repository":{"id":41844630,"uuid":"52037201","full_name":"hjson/hjson-php","owner":"hjson","description":"Hjson for PHP","archived":false,"fork":false,"pushed_at":"2023-10-23T19:32:35.000Z","size":78,"stargazers_count":85,"open_issues_count":4,"forks_count":20,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-03T11:42:13.983Z","etag":null,"topics":["hjson","php"],"latest_commit_sha":null,"homepage":"https://hjson.github.io/","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/hjson.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2016-02-18T20:42:01.000Z","updated_at":"2024-09-17T10:58:23.000Z","dependencies_parsed_at":"2022-08-28T03:00:41.882Z","dependency_job_id":"8aae15ff-bf55-496b-b1ce-37c3eef76a98","html_url":"https://github.com/hjson/hjson-php","commit_stats":{"total_commits":47,"total_committers":14,"mean_commits":3.357142857142857,"dds":0.7446808510638299,"last_synced_commit":"77d46ed6392ac24ef845cd7e01091e2de7e62840"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjson%2Fhjson-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjson%2Fhjson-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjson%2Fhjson-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjson%2Fhjson-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hjson","download_url":"https://codeload.github.com/hjson/hjson-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247427006,"owners_count":20937201,"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":["hjson","php"],"created_at":"2024-08-07T01:01:38.450Z","updated_at":"2025-04-06T03:08:21.336Z","avatar_url":"https://github.com/hjson.png","language":"PHP","readme":"# hjson-php\n\n[![Build Status](https://github.com/hjson/hjson-php/workflows/test/badge.svg)](https://github.com/hjson/hjson-php/actions)\n[![Packagist](https://img.shields.io/packagist/v/laktak/hjson.svg?style=flat-square)](https://packagist.org/packages/laktak/hjson)\n\n[Hjson](https://hjson.github.io), the Human JSON. A configuration file format for humans. Relaxed syntax, fewer mistakes, more comments.\n\n![Hjson Intro](https://hjson.github.io/hjson1.gif)\n\n```\n{\n  # specify rate in requests/second (because comments are helpful!)\n  rate: 1000\n\n  // prefer c-style comments?\n  /* feeling old fashioned? */\n\n  # did you notice that rate doesn't need quotes?\n  hey: look ma, no quotes for strings either!\n\n  # best of all\n  notice: []\n  anything: ?\n\n  # yes, commas are optional!\n}\n```\n\nThe PHP implementation of Hjson is based on [hjson-js](https://github.com/hjson/hjson-js). For other platforms see [hjson.github.io](https://hjson.github.io).\n\n# Install from composer\n\n```\ncomposer require laktak/hjson\n```\n\n# Usage\n\n```\nuse HJSON\\HJSONParser;\nuse HJSON\\HJSONStringifier;\n\n$parser = new HJSONParser();\n$obj = $parser-\u003eparse(hjsonText);\n\n$stringifier = new HJSONStringifier();\n$text = $stringifier-\u003estringify($obj);\n```\n\n\n# API\n\n### HJSONParser: parse($text, $options)\n\nThis method parses *JSON* or *Hjson* text to produce an object or array.\n\n- *text*: the string to parse as JSON or Hjson\n- *options*: array\n  - *keepWsc*: boolean, keep white space and comments. This is useful if you want to edit an hjson file and save it while preserving comments (default false)\n  - *assoc*: boolean, return associative array instead of object (default false)\n\n### HJSONStringifier: stringify($value, $options)\n\nThis method produces Hjson text from a value.\n\n- *value*: any value, usually an object or array.\n- *options*: array\n  - *keepWsc*: boolean, keep white space. See parse.\n  - *bracesSameLine*: boolean, makes braces appear on the same line as the key name. Default false.\n  - *quotes*: string, controls how strings are displayed.\n    - \"min\": no quotes whenever possible (default)\n    - \"always\": always use quotes\n  - *space*: specifies the indentation of nested structures. If it is a number, it will specify the number of spaces to indent at each level. If it is a string (such as '\\t' or '\u0026nbsp;'), it contains the characters used to indent at each level.\n  - *eol*: specifies the EOL sequence\n\n\n## modify \u0026 keep comments\n\nYou can modify a Hjson file and keep the whitespace \u0026 comments intact. This is useful if an app updates its config file.\n\n```\n$parser = new HJSONParser();\n$stringifier = new HJSONStringifier();\n\n$text = \"{\n  # specify rate in requests/second (because comments are helpful!)\n  rate: 1000\n\n  // prefer c-style comments?\n  /* feeling old fashioned? */\n\n  # did you notice that rate doesn't need quotes?\n  hey: look ma, no quotes for strings either!\n\n  # best of all\n  notice: []\n  anything: ?\n\n  # yes, commas are optional!\n\n  array: [\n    // hello\n    0\n    1\n    2\n  ]\n}\";\n\n// Parse, keep whitespace and comments\n$data = $parser-\u003eparseWsc($text);\n\n// Modify like you normally would\n$data-\u003erate = 500;\n\n// You can also edit comments by accessing __WSC__\n$wsc1 = \u0026$data-\u003e__WSC__; // for objects\n$wsc2 = \u0026$data-\u003earray['__WSC__']; // for arrays\n\n// __WSC__ for objects contains { c: {}, o: [] }\n// - c with the actual comment and, firts comment is key ' '\n// - o (array) with the order of the members\n$emptyKey = \" \";\n$wsc1-\u003ec-\u003e$emptyKey = \"\\n  # This is the first comment\";\n$wsc1-\u003ec-\u003erate = \"\\n  # This is the comment after rate\";\n\n// Sort comments order just because we can\nsort($wsc1-\u003eo);\n\n// Edit array comments\n$wsc2[0] .= ' world';\n\n// convert back to Hjson\n$text2 = $stringifier-\u003estringifyWsc($data);\n```\n\n# History\n\n[see releases](https://github.com/hjson/hjson-php/releases)\n","funding_links":[],"categories":["php"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhjson%2Fhjson-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhjson%2Fhjson-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhjson%2Fhjson-php/lists"}