Skip to content

lokhman/json-zeroer

Repository files navigation

json-zeroer - Zero-friendly JSON patch for Go

Build Status codecov License

Implementation of Go issue #11939 that uses memory hack known as "monkey patching" presented by Bouke van der Bijl.

Install

go get github.com/lokhman/json-zeroer

Usage

package main

import (
    "encoding/json"
    "time"
    
    _ "github.com/lokhman/json-zeroer"
)

type Object struct {
    X string    `json:"x,omitempty"`
    Y time.Time `json:"y,omitempty"`
    Z time.Time `json:"z,omitempty"`
}

func main() {
    o := Object{Y: time.Now()}
    data, err := json.Marshal(o)
    if err != nil {
        panic(err)
    }
    println(string(data)) // {"y":"2018-03-15T19:44:50Z"}
}

See examples for more examples.

Tests

Use go test for testing.

Notes

Library should work in Linux and Windows OS both x32 and x64. As library uses direct memory access, I would recommend to use it with caution. Other limitations are listed here: https://github.com/bouk/monkey#notes.

License

Library is available under the MIT license. The included LICENSE file describes this in detail.

About

Zero-friendly JSON patch for Go

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages