{"id":21690593,"url":"https://github.com/reiver/go-json","last_synced_at":"2026-05-21T07:31:19.408Z","repository":{"id":252175382,"uuid":"839643193","full_name":"reiver/go-json","owner":"reiver","description":"Package json implements JSON encoders and decoders, for the Go programming language. Package json is meant to be a replacement for the Go built-in \"encoding/json\" package. Package json also includes a number of addtional useful features (that the Go built-in \"encoding/json\" package does not have).","archived":false,"fork":false,"pushed_at":"2024-12-13T10:59:55.000Z","size":130,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-25T13:08:06.767Z","etag":null,"topics":["json"],"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/reiver.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}},"created_at":"2024-08-08T03:25:54.000Z","updated_at":"2024-12-13T10:59:59.000Z","dependencies_parsed_at":"2024-08-28T01:59:37.913Z","dependency_job_id":"ec8a7260-9514-4f30-aad6-f8b1a89634c1","html_url":"https://github.com/reiver/go-json","commit_stats":null,"previous_names":["reiver/go-json"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reiver%2Fgo-json","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reiver%2Fgo-json/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reiver%2Fgo-json/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reiver%2Fgo-json/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reiver","download_url":"https://codeload.github.com/reiver/go-json/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244618428,"owners_count":20482316,"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":["json"],"created_at":"2024-11-25T17:32:22.224Z","updated_at":"2026-05-21T07:31:19.403Z","avatar_url":"https://github.com/reiver.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# go-json\n\nPackage **json** implements JSON encoders and decoders, for the Go programming-language (golang).\n\nPackage **json** is meant to be a replacement for the Go built-in `\"encoding/json\"` package.\n\nPackage **json** also includes a number of addtional useful features (that the Go built-in `\"encoding/json\"` package does _not_ have).\n\nPackage **json** is a custom JSON encoding/decoding library for the Go programming-language (golang), designed as a replacement for the Go built-in`\"encoding/json\"` package with additional features like _custom modifiers_, _constant fields_, and _extended struct tag support_.\n\n## Documention\n\nOnline documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-json\n\n[![GoDoc](https://godoc.org/github.com/reiver/go-json?status.svg)](https://godoc.org/github.com/reiver/go-json)\n\n## Examples\n\nTo marshal a Go value to JSON, you can do something similar to the following:\n\n```golang\nimport \"github.com/reiver/go-json\"\n\n// ...\n\njsonBytes, err := json.Marshal(value)\n```\n\nTo unmarshal a JSON value to Go, you can do something similar to the following:\n\n```golang\nimport \"github.com/reiver/go-json\"\n\n// ...\n\nerr := json.Unmarshal(jsonBytes, \u0026value)\n```\n\n## Custom Modifiers\n\nPackage **json** supports _custom modifiers_ through struct tags.\nA modifier transforms the already-marshaled JSON bytes of a struct field.\n\n### Tag Format\n\n```golang\nField Type `json:\"name,modifier1,modifier2,...\"`\n```\n\nAny struct tag option that isn't `omitempty`, `nullempty`, or `-` is treated as a modifier name.\nMultiple modifiers are applied in order, left to right.\n\n### Built-in Modifiers\n\nThe `DefaultUsher` (used by `json.Marshal`) comes with two built-in modifiers:\n\n**`string`** — wraps the marshaled value in quotes:\n\n```golang\ntype MyStruct struct {\n\tBanana int `json:\"banana,string\"`\n}\n\n// Banana with value 5 produces: {\"banana\":\"5\"}\n```\n\n**`bare`** — strips quotes from a JSON string, outputting the raw content:\n\n```golang\ntype MyStruct struct {\n\tBanana string `json:\"banana,bare\"`\n}\n\n// Banana with value \"true\" produces: {\"banana\":true}\n```\n\n### Registering Custom Modifiers\n\nYou can register your own modifiers on an `Usher` instance:\n\n```golang\nvar usher json.Usher\n\nusher.ImplantModifier(\"digest\", func(data []byte) ([]byte, error) {\n\t// transform the marshaled bytes\n\t// ...\n\treturn transformed, nil\n})\n\njsonBytes, err := usher.Marshal(value)\n```\n\nA `ModifierFunc` has the signature `func([]byte) ([]byte, error)`.\nIt receives the marshaled JSON bytes for a field and returns the transformed bytes.\n\nModifiers can be chained:\n\n```golang\nField string `json:\"field,omitempty,string,mymod\"`\n```\n\nThis applies `string` first, then `mymod`.\nIf any modifier returns an `ErrorEmpty` error and the field has `omitempty`, the field is omitted from the output.\nIf the field has `nullempty` instead, the field outputs `null`.\n\nTo add a custom modifier to the global `DefaultUsher` (so it works with `json.Marshal`):\n\n```golang\njson.DefaultUsher.ImplantModifier(\"mymod\", myModifierFunc)\n```\n\n## Null Empty (`nullempty`)\n\nThe `nullempty` struct tag option outputs JSON `null` for a field when its value is empty, instead of omitting the field entirely (which is what `omitempty` does).\n\n```golang\ntype MyStruct struct {\n\tName  string   `json:\"name\"`\n\tValue string   `json:\"value,nullempty\"`\n\tItems []string `json:\"items,nullempty\"`\n}\n\n// With zero values produces: {\"name\":\"\",\"value\":null,\"items\":null}\n```\n\nEmptiness is determined using the same checks as `omitempty`:\n- Types implementing `Emptier` (`IsEmpty() bool`)\n- Types implementing `Nothinger` (`IsNothing() bool`)\n- Zero values (via `reflect.DeepEqual`)\n- Empty slices, maps, and arrays (length 0)\n\nWhen a type implements `Emptier` or `Nothinger`, that interface is trusted and the fallback zero-value/length checks are not applied.\n\nIf a `MarshalJSON()` method or a modifier returns an `ErrorEmpty` error and the field has `nullempty`, the field outputs `null` instead of being omitted.\n\n## Installation\n\nTo install package **json** do the following:\n```\nGOPROXY=direct go get github.com/reiver/go-json\n```\n\n## Author\n\nPackage **json** was written by [Charles Iliya Krempeaux](http://reiver.link)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freiver%2Fgo-json","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freiver%2Fgo-json","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freiver%2Fgo-json/lists"}