Skip to content

voxelbrain/jsonext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonext is a package augmenting Go’s core package encoding/json. jsonext was written out of the need to catch unexpected fields of a JSON object in a map.

Usage

jsonext is supposed to be a drop-in replacement for the encoding/json package. The recommended usage is

import (
	// ...
	json "github.com/voxelbrain/jsonext"
	// ...
)

Note: The API of encoding/json has not been completely mirrored yet. As of now, it is not an actual drop-in replacement.

Please see the documentation for details.

Example

func ExampleUnmarshal() {
	var jsonBlob = []byte(`{
		"Name": "Platypus",
		"Order": "Monotremata",
		"Beak": "Yellow",
		"IsAGroundhog": false
	}`)
	type Animal struct {
		Name     string
		Order    string
		CatchAll `jsonext:"catchall"`
	}
	var animal Animal
	err := Unmarshal(jsonBlob, &animal)
	if err != nil {
		fmt.Println("error:", err)
	}
	fmt.Printf("%+v", animal)
	// Output:
	// {Name:Platypus Order:Monotremata CatchAll:map[Beak:Yellow IsAGroundhog:false]}
}

Version 0.1.0

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages