{"id":24083306,"url":"https://github.com/mitranim/jsonfmt","last_synced_at":"2025-04-30T18:23:14.342Z","repository":{"id":57569395,"uuid":"310019256","full_name":"mitranim/jsonfmt","owner":"mitranim","description":"Flexible JSON formatter. Supports comments, multi-line with single-line chunks within width limit, fixes punctuation. Library and optional CLI.","archived":false,"fork":false,"pushed_at":"2025-04-02T08:24:54.000Z","size":44,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-26T06:56:57.077Z","etag":null,"topics":["formatter","json"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitranim.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-11-04T14:00:37.000Z","updated_at":"2025-04-02T08:24:58.000Z","dependencies_parsed_at":"2023-12-24T09:23:04.000Z","dependency_job_id":"b066bdef-5b80-4b04-8d15-52a3e278528e","html_url":"https://github.com/mitranim/jsonfmt","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Fjsonfmt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Fjsonfmt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Fjsonfmt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitranim%2Fjsonfmt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitranim","download_url":"https://codeload.github.com/mitranim/jsonfmt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251758709,"owners_count":21639090,"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":["formatter","json"],"created_at":"2025-01-09T23:56:20.100Z","updated_at":"2025-04-30T18:23:14.330Z","avatar_url":"https://github.com/mitranim.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Overview\n\nFlexible JSON formatter. Features:\n\n* Preserves order.\n* Supports comments (configurable).\n* Supports trailing commas (configurable).\n* Supports max width (configurable).\n  * For dicts and lists: single-line until given width, multi-line after\n    exceeding said width.\n* Fixes missing or broken punctuation.\n* Tiny Go library.\n* Optional tiny CLI.\n* No dependencies.\n\nSee API documentation at https://godoc.org/github.com/mitranim/jsonfmt.\n\nCurrent limitations:\n\n* Always permissive. Unrecognized non-whitespace is treated as arbitrary content on par with strings, numbers, etc.\n* Slower than `json.Indent` from the Go standard library.\n* Input must be UTF-8.\n* No streaming support. Input and output are `[]byte` or `string`.\n  * Streaming support could be added on demand.\n\n## Installation\n\n### Library\n\nTo use this as a library, simply import it:\n\n```go\nimport \"github.com/mitranim/jsonfmt\"\n\nvar formatted string = jsonfmt.Format[string](jsonfmt.Default, `{}`)\nvar formatted string = jsonfmt.FormatString(jsonfmt.Default, `{}`)\nvar formatted []byte = jsonfmt.FormatBytes(jsonfmt.Default, `{}`)\n```\n\n### CLI\n\nFirst, install Go: https://golang.org. Then run this:\n\n```sh\ngo install github.com/mitranim/jsonfmt/jsonfmt@latest\n```\n\nThis will compile the executable into `$GOPATH/bin/jsonfmt`. Make sure `$GOPATH/bin` is in your `$PATH` so the shell can discover the `jsonfmt` command. For example, my `~/.profile` contains this:\n\n```sh\nexport GOPATH=\"$HOME/go\"\nexport PATH=\"$GOPATH/bin:$PATH\"\n```\n\nAlternatively, you can run the executable using the full path. At the time of writing, `~/go` is the default `$GOPATH` for Go installations. Some systems may have a different one.\n\n```sh\n~/go/bin/jsonfmt\n```\n\n## Usage\n\nSee the library documentation on https://godoc.org/github.com/mitranim/jsonfmt.\n\nFor CLI usage, run `jsonfmt -h`.\n\n## Examples\n\n**Supports comments and trailing commas** (all configurable):\n\n```jsonc\n{// Line comment\n\"one\": \"two\", /* Block comment */ \"three\": 40}\n```\n\nOutput:\n\n```jsonc\n{\n  // Line comment\n  \"one\": \"two\",\n  /* Block comment */\n  \"three\": 40,\n}\n```\n\n**Single-line until width limit** (configurable):\n\n```jsonc\n{\n  \"one\": {\"two\": [\"three\"], \"four\": [\"five\"]},\n  \"six\": {\"seven\": [\"eight\"], \"nine\": [\"ten\"], \"eleven\": [\"twelve\"], \"thirteen\": [\"fourteen\"]}\n}\n```\n\nOutput:\n\n```jsonc\n{\n  \"one\": {\"two\": [\"three\"], \"four\": [\"five\"]},\n  \"six\": {\n    \"seven\": [\"eight\"],\n    \"nine\": [\"ten\"],\n    \"eleven\": [\"twelve\"],\n    \"thirteen\": [\"fourteen\"],\n  },\n}\n```\n\n**Fix missing or broken punctuation**:\n\n```jsonc\n{\"one\" \"two\" \"three\" {\"four\" \"five\"} \"six\" [\"seven\": \"eight\"]},,,\n```\n\nOutput:\n\n```jsonc\n{\"one\": \"two\", \"three\": {\"four\": \"five\"}, \"six\": [\"seven\", \"eight\"]}\n```\n\n## License\n\nhttps://unlicense.org\n\n## Misc\n\nI'm receptive to suggestions. If this library _almost_ satisfies you but needs changes, open an issue or chat me up. Contacts: https://mitranim.com/#contacts\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitranim%2Fjsonfmt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitranim%2Fjsonfmt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitranim%2Fjsonfmt/lists"}