{"id":13713278,"url":"https://github.com/tinode/jsonco","last_synced_at":"2025-04-05T10:31:15.512Z","repository":{"id":57521038,"uuid":"251606792","full_name":"tinode/jsonco","owner":"tinode","description":"JSON with C-style comments","archived":false,"fork":false,"pushed_at":"2022-06-20T02:54:40.000Z","size":7,"stargazers_count":8,"open_issues_count":0,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-21T03:06:22.735Z","etag":null,"topics":["go","golang","golang-package","json","json-comment","json-comments"],"latest_commit_sha":null,"homepage":null,"language":"Go","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/tinode.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-31T13:12:33.000Z","updated_at":"2024-09-30T02:22:05.000Z","dependencies_parsed_at":"2022-09-26T18:01:11.052Z","dependency_job_id":null,"html_url":"https://github.com/tinode/jsonco","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/tinode%2Fjsonco","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinode%2Fjsonco/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinode%2Fjsonco/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tinode%2Fjsonco/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tinode","download_url":"https://codeload.github.com/tinode/jsonco/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247324647,"owners_count":20920692,"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":["go","golang","golang-package","json","json-comment","json-comments"],"created_at":"2024-08-02T23:01:31.381Z","updated_at":"2025-04-05T10:31:15.073Z","avatar_url":"https://github.com/tinode.png","language":"Go","funding_links":[],"categories":["Repositories"],"sub_categories":[],"readme":"# Jsonco (commented json)\n\n`jsonco` is an [io.Reader](http://golang.org/pkg/io/#Reader) for JSON which strips C-style comments and trailing commas,\nallowing use of JSON as a *reasonable* config format. It also has a utility method which translates byte offset into the stream\ninto line and character positions for easier error interpretation. The package is aware of multibyte characters.\n\nSingle line comments start with `//` and continue to the end of the line. Multiline comments are enclosed in `/*` and `*/`.\nIf a trailing comma is in front of `]` or `}` it is stripped as well.\n\nThis implementation is used by https://github.com/tinode/chat and as such it's up to date and supported.\n\n\n## Examples\n\nGiven `settings.json`\n\n```js\n{\n\t\"key\": \"value\", // k:v\n\n\t// a list of numbers\n\t\"list\": [1, 2, 3],\n\n\t/* \n\ta list of numbers\n\twhich are important\n\t*/\n\t\"numbers\": [1, 2, 3],\n}\n```\n\nYou can read it in as a *normal* json file:\n\n```go\npackage main\n\nimport (\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"os\"\n\n\t\"github.com/tinode/jsonco\"\n)\n\nfunc main() {\n\tvar v interface{}\n\tf, _ := os.Open(\"settings.json\")\n\t// Wrap the reader before passing it to the json decoder.\n\tjr := jsonco.New(f)\n\tjson.NewDecoder(jr).Decode(\u0026v)\n\tfmt.Println(v)\n}\n```\n\nIf a parsing error is encountered, its location can be found like this:\n\n```go\nif err := json.NewDecoder(jr).Decode(\u0026v); err != nil {\n\tswitch jerr := err.(type) {\n\tcase *json.UnmarshalTypeError:\n\t\tlnum, cnum, _ := jr.LineAndChar(jerr.Offset)\n\t\tfmt.Fatalf(\"Unmarshall error in %s at %d:%d (offset %d bytes): %s\",\n\t\t\tjerr.Field, lnum, cnum, jerr.Offset, jerr.Error())\n\tcase *json.SyntaxError:\n\t\tlnum, cnum, _ := jr.LineAndChar(jerr.Offset)\n\t\tfmt.Fatalf(\"Syntax error at %d:%d (offset %d bytes): %s\",\n\t\t\tlnum, cnum, jerr.Offset, jerr.Error())\n\tdefault:\n\t\tfmt.Fatalln(\"Failed to parse:\", err)\n\t}\n}\n\n```\n\n## Godoc\n\nhttps://pkg.go.dev/github.com/tinode/jsonco?tab=doc\n\n## License\n\nMIT\n\n## References\n\nThis code is forked from https://github.com/DisposaBoy/JsonConfigReader with added go.mod, offset translation\nand multibyte character support.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinode%2Fjsonco","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinode%2Fjsonco","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinode%2Fjsonco/lists"}