{"id":28166566,"url":"https://github.com/daniel-sc/json5-trueformat","last_synced_at":"2026-02-24T20:42:32.818Z","repository":{"id":285964781,"uuid":"959918489","full_name":"daniel-sc/json5-trueformat","owner":"daniel-sc","description":"Typescript JSON/JSON5 parser that 100% retains all formatting for creating identical JSON on roundtrips","archived":false,"fork":false,"pushed_at":"2025-04-29T14:01:55.000Z","size":73,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-01T18:22:24.735Z","etag":null,"topics":["json","json-parser","json5","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/daniel-sc.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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-03T15:03:46.000Z","updated_at":"2025-04-29T14:01:59.000Z","dependencies_parsed_at":"2025-04-03T16:23:22.655Z","dependency_job_id":"5b9159bc-52cb-48d0-9e89-f95453f11da9","html_url":"https://github.com/daniel-sc/json5-trueformat","commit_stats":null,"previous_names":["daniel-sc/json5-trueformat"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/daniel-sc/json5-trueformat","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-sc%2Fjson5-trueformat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-sc%2Fjson5-trueformat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-sc%2Fjson5-trueformat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-sc%2Fjson5-trueformat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/daniel-sc","download_url":"https://codeload.github.com/daniel-sc/json5-trueformat/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/daniel-sc%2Fjson5-trueformat/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268654904,"owners_count":24285124,"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","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","json-parser","json5","typescript"],"created_at":"2025-05-15T13:13:25.903Z","updated_at":"2026-02-24T20:42:27.781Z","avatar_url":"https://github.com/daniel-sc.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm](https://img.shields.io/npm/v/json5-trueformat)](https://www.npmjs.com/package/json5-trueformat)\n[![Coverage Status](https://coveralls.io/repos/github/daniel-sc/json5-trueformat/badge.svg?branch=master)](https://coveralls.io/github/daniel-sc/json5-trueformat?branch=main)\n\n# json5-trueformat\n\njson5-trueformat is a TypeScript library for parsing, editing, and serializing JSON and [JSON5](https://json5.org/) files without losing formatting details.\nIt creates a custom AST that captures every comment, blank line, indentation, and other formatting details to ensure a lossless round-trip.\n\nThis library is inspired by the design of [xml-trueformat](https://github.com/daniel-sc/xml-trueformat) and is ideal for use cases where the exact layout and comment structure of JSON files must be preserved (e.g., configuration files under version control).\nEnjoy seamless, non-destructive editing of your JSON files!\n\n## Features\n\n- **Exact Formatting Preservation** \\\n  Retains inline comments, blank lines, and all whitespace exactly as in the original file.\n\n- **AST-based Editing** \\\n  Provides an abstract syntax tree for precise modifications. Change the value of a key or add new entries without reformatting the rest of the file.\n\n- **Modifications** \\\n  Supports adding, removing, and updating keys and values in JSON5 objects and arrays. Convenient methods are provided to simplify adding entries matching the surrounding formatting.\\\n  See e.g. `JSON5Object.addKeyValue(key, value, options)`.\n\n- **Support for Comments and Whitespace** \\\n  Captures and preserves comments and whitespace within objects and arrays.\\\n  See `JSON5ObjectEntry` and `JSON5ArrayElement`.\n\n## Installation\n\nInstall the dependencies:\n\n```bash\nnpm install json5-trueformat\n```\n\n## Usage\n\nBelow is an example that reads a JSON5 file, updates a value, and writes it back without changing the formatting:\n\n```ts\nimport { parseJSON5, JSON5Document, JSON5Object, JSON5ObjectEntry, JSON5Literal } from 'json5-trueformat';\n\nconst input = `{\n  // This is a comment\n  key_without_quotes : \"value with qutes\",\n  \"key_with_quotes\":'value with single quotes',\n}`;\n\nconst doc = parseJSON5(input);\n\n// expeted AST:\nexpect(doc).toEqual(\n  new JSON5Document(\n    '',\n    new JSON5Object([\n      '\\n  // This is a comment\\n  ',\n      new JSON5ObjectEntry('', 'key_without_quotes', ' ', ' ', new JSON5Literal('value with qutes', '\"'), '  ', ','),\n      '\\n  ',\n      new JSON5ObjectEntry('\"', 'key_with_quotes', '', '', new JSON5Literal('value with single quotes', \"'\"), '', ','),\n      '\\n',\n    ]),\n    '',\n  ),\n);\n\n// modify the value of a key:\n(doc.value as JSON5Object).entries.find((e) =\u003e e instanceof JSON5ObjectEntry)!.value.raw = 'new value';\n\n// add a new key-value pair:\n(doc.value as JSON5Object).addKeyValue('new_key', new JSON5Literal('new value', '\"'));\n\n// expect serialization to preserve the formatting:\nexpect(doc.toString()).toEqual(`{\n  // This is a comment\n  key_without_quotes: \"new value\",\n  \"key_with_quotes\": 'value with single quotes',\n  \"new_key\": \"new value\",\n}`);\n```\n\n## Contributing\n\nContributions, bug reports, and feature requests are welcome!\n\nPlease open an issue or submit a pull request on the GitHub repository.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-sc%2Fjson5-trueformat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdaniel-sc%2Fjson5-trueformat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdaniel-sc%2Fjson5-trueformat/lists"}