{"id":29670606,"url":"https://github.com/wneessen/niljson","last_synced_at":"2025-07-31T22:14:46.388Z","repository":{"id":255438923,"uuid":"850686927","full_name":"wneessen/niljson","owner":"wneessen","description":"🌀 A simple Go package for (un-)marshalling null-able JSON types","archived":false,"fork":false,"pushed_at":"2024-12-18T08:23:42.000Z","size":204,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-18T09:29:22.057Z","etag":null,"topics":["go","golang","hacktoberfest","json","null-safety","unmarshalling"],"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/wneessen.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":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"wneessen","ko_fi":"winni"}},"created_at":"2024-09-01T13:53:52.000Z","updated_at":"2024-12-18T08:23:40.000Z","dependencies_parsed_at":"2024-10-25T09:35:02.295Z","dependency_job_id":"b0091f32-4b68-4907-80c7-f4f7d89839d9","html_url":"https://github.com/wneessen/niljson","commit_stats":null,"previous_names":["wneessen/niljson"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/wneessen/niljson","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wneessen%2Fniljson","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wneessen%2Fniljson/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wneessen%2Fniljson/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wneessen%2Fniljson/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wneessen","download_url":"https://codeload.github.com/wneessen/niljson/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wneessen%2Fniljson/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266561579,"owners_count":23948632,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","hacktoberfest","json","null-safety","unmarshalling"],"created_at":"2025-07-22T19:36:57.576Z","updated_at":"2025-07-22T19:36:58.377Z","avatar_url":"https://github.com/wneessen.png","language":"Go","funding_links":["https://github.com/sponsors/wneessen","https://ko-fi.com/winni","https://ko-fi.com/D1D24V9IX"],"categories":[],"sub_categories":[],"readme":"\u003c!--\nSPDX-FileCopyrightText: 2024 Winni Neessen \u003cwn@neessen.dev\u003e\n\nSPDX-License-Identifier: CC0-1.0\n--\u003e\n\n# niljson - A simple Go package for (un-)marshalling null-able JSON types\n\n[![GoDoc](https://godoc.org/github.com/wneessen/niljson?status.svg)](https://pkg.go.dev/github.com/wneessen/niljson)\n[![codecov](https://codecov.io/gh/wneessen/niljson/branch/main/graph/badge.svg?token=W4QI1RMR4L)](https://codecov.io/gh/wneessen/niljson)\n[![Go Report Card](https://goreportcard.com/badge/github.com/wneessen/niljson)](https://goreportcard.com/report/github.com/wneessen/niljson)\n[![REUSE status](https://api.reuse.software/badge/github.com/wneessen/niljson)](https://api.reuse.software/info/github.com/wneessen/niljson)\n\u003ca href=\"https://ko-fi.com/D1D24V9IX\"\u003e\u003cimg src=\"https://uploads-ssl.webflow.com/5c14e387dab576fe667689cf/5cbed8a4ae2b88347c06c923_BuyMeACoffee_blue.png\" height=\"20\" alt=\"buy ma a coffee\"\u003e\u003c/a\u003e\n\nniljson provides a simple and efficient way to handle nullable JSON fields during the (un-)marshalling process. \nIn JSON, it's common to encounter fields that can be `null`, but handling these fields in Go can be cumbersome, \nespecially when dealing with primitive types like `int`, `float64`, and `bool`. These types can all be either `0` \n(as a value) or `null`. In Go you can always work with pointers, but these can lead to unhandled nil \npointer dereferences.\n\n**niljson** addresses this challenge by offering a set of types that can seamlessly handle `null` values during \nunmarshalling, allowing your Go applications to work with JSON data more naturally and with fewer boilerplate \nchecks for `nil` values.\n\n### Key Features\n\n- **Nullable Types**: Provides a range of nullable types (`NilString`, `NilInt`, `NilFloat`, `NilBool`, etc.) that \n  are easy to use and integrate into your existing Go structs.\n- **JSON Unmarshalling Support**: Automatically handles the (un-)marshalling of JSON fields, converting `null` JSON \n  values to Go's `nil` or zero values, depending on the context.\n- **Minimalistic and Lightweight**: Designed to be lightweight and unobtrusive, so it won't bloat your application \n  or introduce unnecessary dependencies (only relies on the Go standard library)\n\n### Example Usage\n\n```go\npackage main\n\nimport (\n    \"encoding/json\"\n    \"fmt\"\n    \"os\"\n    \n    \"github.com/wneessen/niljson\"\n)\n\ntype JSONType struct {\n    Bool       niljson.NilBoolean `json:\"bool\"`\n    Float32    niljson.NilFloat32 `json:\"float32,omitempty\"`\n    Float64    niljson.NilFloat64 `json:\"float64\"`\n    Int        niljson.NilInt     `json:\"int\"`\n    Int64      niljson.NilInt64   `json:\"int64\"`\n    NullString niljson.NilString  `json:\"nil\"`\n    String     niljson.NilString  `json:\"string\"`\n}\n\nfunc main() {\n  data := []byte(`{\n \t\t\"bytes\": \"Ynl0ZXM=\",\n\t\t\"bool\": true,\n\t\t\"float32\": null,\n\t\t\"float64\":0,\n\t\t\"int\": 123,\n\t\t\"int64\": 12345678901234,\n\t\t\"nilvalue\": null,\n\t\t\"string\":\"test\"\n\t}`)\n\n  var example JSONType\n  var output string\n  if err := json.Unmarshal(data, \u0026example); err != nil {\n    fmt.Println(\"failed to unmarshal JSON:\", err)\n    os.Exit(1)\n  }\n\n  if example.Bool.NotNil() {\n    output += fmt.Sprintf(\"Bool is: %t, \", example.Bool.Value())\n  }\n  if example.Float32.IsNil() {\n    output += \"Float 32 is nil, \"\n  }\n  if example.Float64.NotNil() {\n    output += fmt.Sprintf(\"Float 64 is: %f, \", example.Float64.Value())\n  }\n  if example.String.NotNil() {\n    output += fmt.Sprintf(\"String is: %s\", example.String.Value())\n  }\n  fmt.Println(output)\n  \n  data, err := json.Marshal(\u0026example)\n  if err != nil {\n    fmt.Printf(\"failed to marshal JSON: %s\", err)\n    os.Exit(1)\n  }\n  fmt.Println(data)\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwneessen%2Fniljson","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwneessen%2Fniljson","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwneessen%2Fniljson/lists"}