Turns the lenient JSON that Content Patcher and Json.NET accept (comments, trailing commas, loose numbers) into strict JSON for encoding/json. Package lenientjson, module github.com/Rethunk-Tech/go-lenientjson.
One function, Clean, takes the bytes a .NET program would hand to Json.NET (Newtonsoft.Json) and returns strict JSON that encoding/json reads to the same values. The target is Json.NET's reader, not JSONC or JSON5. A caller that needs the cleaned bytes (for json.Decoder, a line-numbered error) gets them; one that does not writes json.Unmarshal(lenientjson.Clean(b), &v).
go get github.com/Rethunk-Tech/go-lenientjsonA worked example and the contracts: HUMANS.md.
- Reads the encoding
File.ReadAllTextpicks from the BOM: UTF-8, UTF-16 LE/BE, UTF-32 LE/BE. - Strips
//and/* */comments and trailing commas; an elided array element or empty property value ([1,,2],{"o":,}) becomesnull. - Accepts single-quoted strings, unquoted property names,
.5and5., and raw control characters in strings. NaN,Infinity,-Infinityandundefinedbecomenull, becauseencoding/jsonhas no NaN.- Keeps every newline, so a
*json.SyntaxError's line over the output is the line in the source. Columns are not kept. - Known gap: hex (
0x1F) and octal (012) integers stay invalid; Json.NET reads them, but a rewrite depends on the target type.
| Doc | Audience |
|---|---|
| HUMANS.md | Running and using the package |
| AGENTS.md | Internals, invariants, and why |
| CONTRIBUTING.md | Process — commits, tests, docs |
| SECURITY.md | Vulnerability disclosure |
| CHANGELOG.md | Release notes |
MIT — see LICENSE. © 2026 Rethunk.Tech, LLC.