Skip to content

echlebek/strictjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

strictjson

Validate JSON objects against Go structs.

Build Status GoDoc

strictjson.Check allows you to check if all of the fields in a struct are satisfied by the incoming JSON message.

Example:

type Foo struct {
	A int    `json:"a"`
	B string `json:"b"`
}

func (f *Foo) UnmarshalJSON(b []byte) error {
	type __ Foo
	var g __
	if err := Check(b, f); err != nil {
		return err
	}
	if err := json.Unmarshal(b, &g); err != nil {
		return err
	}
	*f = Foo(g)
	return nil
}

In the above example, if a user tries to supply a json message that doesn't contain keys a and b, strictjson.Check will return an error.

About

Validate JSON objects against Go structs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages