{"id":13468643,"url":"https://github.com/hjson/hjson-js","last_synced_at":"2025-05-15T02:08:58.889Z","repository":{"id":15192774,"uuid":"17920904","full_name":"hjson/hjson-js","owner":"hjson","description":"Hjson for JavaScript","archived":false,"fork":false,"pushed_at":"2024-02-17T18:11:44.000Z","size":375,"stargazers_count":421,"open_issues_count":24,"forks_count":47,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-05-08T18:53:13.260Z","etag":null,"topics":["hjson","javascript"],"latest_commit_sha":null,"homepage":"https://hjson.github.io/","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/hjson.png","metadata":{"files":{"readme":"README.md","changelog":"history.md","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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-03-19T21:24:05.000Z","updated_at":"2025-04-16T11:41:42.000Z","dependencies_parsed_at":"2024-06-18T12:23:58.331Z","dependency_job_id":"d5af30c5-32dd-46c7-8663-04c57599328f","html_url":"https://github.com/hjson/hjson-js","commit_stats":{"total_commits":134,"total_committers":11,"mean_commits":"12.181818181818182","dds":0.5373134328358209,"last_synced_commit":"5734a70a17b94f12b59081aa6fdf966aac066b23"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjson%2Fhjson-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjson%2Fhjson-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjson%2Fhjson-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hjson%2Fhjson-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hjson","download_url":"https://codeload.github.com/hjson/hjson-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254259384,"owners_count":22040820,"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","javascript"],"created_at":"2024-07-31T15:01:15.546Z","updated_at":"2025-05-15T02:08:55.093Z","avatar_url":"https://github.com/hjson.png","language":"JavaScript","readme":"# hjson-js\n\n[![Build Status](https://img.shields.io/travis/hjson/hjson-js.svg?style=flat-square)](http://travis-ci.org/hjson/hjson-js)\n[![NPM version](https://img.shields.io/npm/v/hjson.svg?style=flat-square)](http://www.npmjs.com/package/hjson)\n[![License](https://img.shields.io/github/license/hjson/hjson-js.svg?style=flat-square)](https://github.com/hjson/hjson-js/blob/master/LICENSE)\n\n[Hjson](https://hjson.github.io), a user interface for JSON\n\n![Hjson Intro](https://hjson.github.io/hjson1.gif)\n\nJSON is easy for humans to read and write... in theory. In practice JSON gives us plenty of opportunities to make mistakes without even realizing it.\n\nHjson is a syntax extension to JSON. It's NOT a proposal to replace JSON or to incorporate it into the JSON spec itself. It's intended to be used like a user interface for humans, to read and edit before passing the JSON data to the machine.\n\n```Hjson\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 JavaScript implementation of Hjson is based on [JSON-js](https://github.com/douglascrockford/JSON-js). For other platforms see [hjson.github.io](https://hjson.github.io).\n\n# Install from npm\n\n```\nnpm install hjson\n```\n\n# Usage\n\n```\nvar Hjson = require('hjson');\n\nvar obj = Hjson.parse(hjsonText);\nvar text2 = Hjson.stringify(obj);\n```\n\nTo keep comments intact see [API](#modify--keep-comments).\n\n## From the Commandline\n\nInstall with `npm install hjson -g`.\n\n```\nUsage:\n  hjson [OPTIONS]\n  hjson [OPTIONS] INPUT\n  hjson (-h | --help | -?)\n  hjson (-V | --version)\n\nINPUT can be in JSON or Hjson format. If no file is given it will read from stdin.\nThe default is to output as Hjson.\n\nOptions:\n  (-j | -json)  output as formatted JSON.\n  (-c | -json=compact)  output as JSON.\nOptions for Hjson output:\n  -sl         output the opening brace on the same line\n  -quote      quote all strings\n  -quote=all  quote keys as well\n  -js         output in JavaScript/JSON compatible format\n              can be used with -rt and // comments\n  -rt         round trip comments\n  -nocol      disable colors\n  -cond=n     set condense option (default 60, 0 to disable)\n\nDomain specific formats are optional extensions to Hjson and can be enabled with the following options:\n  +math: support for Inf/inf, -Inf/-inf, Nan/naN and -0\n  +hex: parse hexadecimal numbers prefixed with 0x\n  +date: support ISO dates\n```\n\nSample:\n- run `hjson -j test.hjson \u003e test.json` to convert to JSON\n- run `hjson test.json \u003e test.hjson` to convert to Hjson\n- run `hjson test.json` to view colorized output\n\n\n# API\n\nThe API is the same for the browser and node.js version.\n\n**NOTE that the DSF api is considered experimental**\n\n### Hjson.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*: object\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\n### Hjson.stringify(value, options)\n\nThis method produces Hjson text from a JavaScript value.\n\n- *value*: any JavaScript value, usually an object or array.\n- *options*: object\n  - *keepWsc*: boolean, keep white space. See parse.\n  - *condense*: integer, will try to fit objects/arrays onto one line. Default 0 (off).\n  - *bracesSameLine*: boolean, makes braces appear on the same line as the key name. Default false.\n  - *emitRootBraces*: boolean, show braces for the root object. Default true.\n  - *quotes*: string, controls how strings are displayed. (setting separator implies \"strings\")\n    - \"min\": no quotes whenever possible (default)\n    - \"keys\": use quotes around keys\n    - \"strings\": use quotes around string values\n    - \"all\": use quotes around keys and string values\n  - *multiline*: string, controls how multiline strings are displayed. (setting quotes implies \"off\")\n    - \"std\": strings containing \\n are shown in multiline format (default)\n    - \"no-tabs\": like std but disallow tabs\n    - \"off\": show in JSON format\n  - *separator*: boolean, output a comma separator between elements. Default false\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 (default is set by Hjson.setEndOfLine())\n  - *colors*: boolean, output ascii color codes\n  - *sortProps*: boolean, when serializing objects into hjson, order the keys based on their UTF-16 code units order. Default false.\n\n### Hjson.endOfLine(), .setEndOfLine(eol)\n\nGets or sets the stringify EOL sequence ('\\n' or '\\r\\n'). When running with node.js this defaults to os.EOL.\n\n### Hjson.rt { parse, stringify }\n\nThis is a shortcut to roundtrip your comments when reading and updating a config file. It is the same as specifying the keepWsc option for the parse and stringify functions.\n\n### Hjson.version\n\nThe version number.\n\n### require-hook\n\nRequire a config file directly.\n\n```\nrequire(\"hjson/lib/require-config\");\nvar cfg=require(\"./config.hjson\");\n```\n\n## modify \u0026 keep comments\n\nYou can modify a Hjson file and keep the whitespace \u0026 comments intact (round trip). This is useful if an app updates its config file.\n\n```\n// parse, keep whitespace and comments\n// (they are stored in a non enumerable __COMMENTS__ member)\nvar data = Hjson.rt.parse(text);\n\n// modify like you normally would\ndata.foo = \"text\";\n\n// convert back to Hjson\nconsole.log(Hjson.rt.stringify(data));\n```\n# Build\n\nTo run all tests and create the bundle output, first install the dev dependencies with `npm i` and then run `npm run build`.\n\n# History\n\n[see history.md](history.md)\n\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhjson%2Fhjson-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhjson%2Fhjson-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhjson%2Fhjson-js/lists"}