{"id":15355072,"url":"https://github.com/adhocore/jsonc","last_synced_at":"2025-04-15T06:17:48.440Z","repository":{"id":63452755,"uuid":"564733926","full_name":"adhocore/jsonc","owner":"adhocore","description":"Golang (v1.13+) JSON5 preprocessor supporting comments, trailing comma, unquoted key/single-quoted string, hex number, trailing decimal point, literal newlines and more.","archived":false,"fork":false,"pushed_at":"2023-03-25T14:24:02.000Z","size":48,"stargazers_count":18,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T06:17:39.242Z","etag":null,"topics":["adhocore","go","golang","json","json-comment","json-parser","json-processor","json5","json5-parser"],"latest_commit_sha":null,"homepage":"","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/adhocore.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"adhocore","custom":["https://paypal.me/ji10"]}},"created_at":"2022-11-11T11:22:30.000Z","updated_at":"2025-01-30T21:28:43.000Z","dependencies_parsed_at":"2024-06-19T17:40:51.423Z","dependency_job_id":"9a9ee012-6792-495c-b555-2dcf20bfc4f4","html_url":"https://github.com/adhocore/jsonc","commit_stats":{"total_commits":22,"total_committers":2,"mean_commits":11.0,"dds":"0.045454545454545414","last_synced_commit":"7b115dfaa6cbebdf23f3b0f3e54c71292757e095"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhocore%2Fjsonc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhocore%2Fjsonc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhocore%2Fjsonc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adhocore%2Fjsonc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adhocore","download_url":"https://codeload.github.com/adhocore/jsonc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249016647,"owners_count":21198833,"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":["adhocore","go","golang","json","json-comment","json-parser","json-processor","json5","json5-parser"],"created_at":"2024-10-01T12:22:23.612Z","updated_at":"2025-04-15T06:17:48.421Z","avatar_url":"https://github.com/adhocore.png","language":"Go","readme":"# adhocore/jsonc\n\n[![Latest Version](https://img.shields.io/github/release/adhocore/jsonc.svg?style=flat-square)](https://github.com/adhocore/jsonc/releases)\n[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)\n[![Go Report](https://goreportcard.com/badge/github.com/adhocore/jsonc)](https://goreportcard.com/report/github.com/adhocore/jsonc)\n[![Test](https://github.com/adhocore/jsonc/actions/workflows/test-action.yml/badge.svg)](https://github.com/adhocore/jsonc/actions/workflows/test-action.yml)\n[![Codecov](https://img.shields.io/codecov/c/github/adhocore/jsonc/main.svg?style=flat-square)](https://codecov.io/gh/adhocore/jsonc)\n[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=Lightweight+fast+and+deps+free+commented+json+parser+for+Golang\u0026url=https://github.com/adhocore/jsonc\u0026hashtags=go,golang,parser,json,json-comment)\n[![Support](https://img.shields.io/static/v1?label=Support\u0026message=%E2%9D%A4\u0026logo=GitHub)](https://github.com/sponsors/adhocore)\n\u003c!-- [![Donate 15](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square\u0026label=donate+15)](https://www.paypal.me/ji10/15usd)\n[![Donate 25](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square\u0026label=donate+25)](https://www.paypal.me/ji10/25usd)\n[![Donate 50](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square\u0026label=donate+50)](https://www.paypal.me/ji10/50usd) --\u003e\n\n\n- Lightweight [JSON5](https://json5.org) pre-processor library for Go. See [#1](https://github.com/adhocore/jsonc/issues/1)\n- Parses JSON5 input to JSON that Go understands. (Think of it as a superset to JSON.)\n- Makes possible to have comment in any form of JSON data.\n- Supported comments: single line `// comment` or multi line `/* comment */`.\n- Supports trailing comma at the end of array or object, eg:\n    - `[1,2,,]` =\u003e `[1,2]`\n    - `{\"x\":1,,}` =\u003e `{\"x\":1}`\n- Supports single quoted string.\n- Supports object keys without quotes.\n- Handles literal LF (linefeed) in string for splitting long lines.\n- Supports explicit positive and hex number. `{\"change\": +10, \"hex\": 0xffff}`\n- Supports decimal numbers with leading or trailing period. `{\"leading\": .5, \"trailing\": 2.}`\n- Supports JSON string inside JSON string.\n- Zero dependency (no vendor bloat).\n\n---\n### Example\n\nThis is [example](./examples/test.json5) of the JSON that you can parse with `adhocore/jsonc`:\n\n```json5\n/*start*/\n//..\n{\n    // this is line comment\n    a: [ // unquoted key\n        'bb', // single quoted string\n        \"cc\", // double quoted string\n    /* multi line\n     * comment\n     */\n        123, // number\n        +10, // +ve number, equivalent to 10\n        -20, // -ve number\n        .25, // floating number, equivalent to 0.25\n        5.,  // floating number, equivalent to 5.0\n        0xabcDEF, // hex base16 number, equivalent to base10 counterpart: 11259375\n        {\n            123: 0xf, // even number as key?\n            xx: [1, .1, 'xyz',], y: '2', // array inside object, inside array\n        },\n        \"// not a comment\",\n        \"/* also not a comment */\",\n        ['', \"\", true, false, null, 1, .5, 2., 0xf, // all sort of data types\n            {key:'val'/*comment*/,}], // object inside array, inside array\n        'single quoted',\n    ],\n    /*aa*/aa: ['AA', {in: ['a', \"b\", ],},],\n    'd': { // single quoted key\n        t: /*creepy comment*/true, 'f': false,\n        a_b: 1, _1_z: 2, Ḁẟḕỻ: 'ɷɻɐỨẞṏḉ', // weird keys?\n        \"n\": null /*multiple trailing commas?*/,,,\n        /* 1 */\n        /* 2 */\n    },\n    \"e\": 'it\\'s \"good\", eh?', // double quoted key, single quoted value with escaped quote\n    // json with comment inside json with comment, read that again:\n    \"g\": \"/*comment*/{\\\"i\\\" : 1, \\\"url\\\" : \\\"http://foo.bar\\\" }//comment\",\n    \"h\": \"a new line after word 'literal'\nthis text is in a new line as there is literal EOL just above. \\\nbut this one is continued in same line due to backslash escape\",\n    // 1.\n    // 2.\n}\n//..\n/*end*/\n```\n\nFind jsonc in [pkg.go.dev](https://pkg.go.dev/github.com/adhocore/jsonc).\n\n## Installation\n\n```sh\ngo get -u github.com/adhocore/jsonc\n```\n\n## Usecase\n\nYou would ideally use this for organizing JSON configurations for humans to read and manage.\nThe JSON5 input is processed down into JSON which can be Unmarshal'ed by `encoding/json`.\n\nFor performance reasons you may also use [cached decoder](#cached-decoder) to have a cached copy of processed JSON output.\n\n## Usage\n\nImport and init library:\n```go\nimport (\n\t\"fmt\"\n\t\"github.com/adhocore/jsonc\"\n)\n\nj := jsonc.New()\n```\n\nStrip and parse:\n```go\njson := []byte(`{\n\t// single line comment\n\t\"a'b\": \"apple'ball\",\n\t/* multi line\n\t   comment */\n\t\"cat\": [\n\t\t\"dog\",\n\t\t\"// not a comment\",\n\t\t\"/* also not a comment */\",\n\t],\n\t\"longtext\": \"long text in\n\tmultple lines\",\n}`)\n\nvar out map[string]interface{}\n\nj.Unmarshall(json, \u0026out)\nfmt.Printf(\"%+v\\n\", out)\n```\n\nStrip comments/commas only:\n```go\njson := []byte(`{\"some\":\"json\",}`)\njson = j.Strip(json)\n```\n\nUsing strings instead of byte array:\n```go\njson := `{\"json\": \"some\n\ttext\",// comment\n\t\"array\": [\"a\",]\n}`\njson = j.StripS(json)\n```\n\nParsing from JSON file directly:\n```go\nvar out map[string]interface{}\n\nj.UnmarshalFile(\"./examples/test.json5\", \u0026out)\nfmt.Printf(\"%+v\\n\", out)\n```\n\n### Cached Decoder\n\nIf you are weary of parsing same JSON5 source file over and over again, you can use cached decoder.\nThe source file is preprocessed and cached into output file with extension `.cached.json`.\nIt syncs the file `mtime` (aka modified time) from JSON5 source file to the cached JSON file to detect change.\n\nThe output file can then be consumed readily by `encoding/json`.\nLeave that cached output untouched for machine and deal with source file only.\n\u003e (You can add `*.cached.json` to `.gitignore` if you so wish.)\n\nAs an example [examples/test.json5](./examples/test.json5) will be processed and cached into `examples/test.cached.json`.\n\nEvery change in source file `examples/test.json5` is reflected to the cached output on next call to `Decode()`\nthus always maintaining the sync.\n\n```go\nimport (\n    \"fmt\"\n    \"github.com/adhocore/jsonc\"\n)\n\nvar dest map[string]interface{}\nerr := jsonc.NewCachedDecoder().Decode(\"./examples/test.json5\", \u0026dest);\nif err != nil {\n    fmt.Printf(\"%+v\", err)\n} else {\n    fmt.Printf(\"%+v\", dest)\n}\n```\n\n\u003e Run working [examples](./examples/main.go) with `go run examples/main.go`.\n\n---\n## License\n\n\u003e \u0026copy; [MIT](./LICENSE) | 2022-2099, Jitendra Adhikari\n\n---\n### Other projects\nMy other golang projects you might find interesting and useful:\n\n- [**gronx**](https://github.com/adhocore/gronx) - Lightweight, fast and dependency-free Cron expression parser (due checker, next run finder), task scheduler and/or daemon for Golang (tested on v1.13 and above) and standalone usage.\n- [**urlsh**](https://github.com/adhocore/urlsh) - URL shortener and bookmarker service with UI, API, Cache, Hits Counter and forwarder using postgres and redis in backend, bulma in frontend; has [web](https://urlssh.xyz) and cli client.\n- [**fast**](https://github.com/adhocore/fast) - Check your internet speed with ease and comfort right from the terminal.\n- [**goic**](https://github.com/adhocore/goic) - Go Open ID Connect, is OpenID connect client library for Golang, supports the Authorization Code Flow of OpenID Connect specification.\n- [**chin**](https://github.com/adhocore/chin) - A Golang command line tool to show a spinner as user waits for some long running jobs to finish.\n","funding_links":["https://github.com/sponsors/adhocore","https://paypal.me/ji10","https://www.paypal.me/ji10/15usd","https://www.paypal.me/ji10/25usd","https://www.paypal.me/ji10/50usd"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadhocore%2Fjsonc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadhocore%2Fjsonc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadhocore%2Fjsonc/lists"}