GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - koki/json: Fork of golang's encoding/json: now with more validation and error context

BranchesTags
Open more actions menu

Latest commit

 

History

15 Commits
15 Commits

Folders and files

NameName
Last commit message
Last commit date
jsonutil
jsonutil
 
 
scripts
scripts
 
 
testdata
testdata
 
 
vendor/github.com
vendor/github.com
 
 
LICENSE.txt
LICENSE.txt
 
 
README.md
README.md
 
 
bench_test.go
bench_test.go
 
 
decode.go
decode.go
 
 
decode_test.go
decode_test.go
 
 
encode.go
encode.go
 
 
encode_test.go
encode_test.go
 
 
example_marshaling_test.go
example_marshaling_test.go
 
 
example_test.go
example_test.go
 
 
fold.go
fold.go
 
 
fold_test.go
fold_test.go
 
 
glide.lock
glide.lock
 
 
glide.yaml
glide.yaml
 
 
indent.go
indent.go
 
 
number_test.go
number_test.go
 
 
scanner.go
scanner.go
 
 
scanner_test.go
scanner_test.go
 
 
stream.go
stream.go
 
 
stream_test.go
stream_test.go
 
 
tables.go
tables.go
 
 
tagkey_test.go
tagkey_test.go
 
 
tags.go
tags.go
 
 
tags_test.go
tags_test.go
 
 

Repository files navigation

Koki's JSON library

It's a fork that makes encoding/json better for users.

Features

  • Annotates decoder errors with the path (e.g. $.pod.container.0.env) where the error occurred. The golang built-in implementation doesn't contextualize errors, so it's hard to track down where they came from.

  • Check for extraneous fields in your JSON, which is useful for detecting misspelled keys and other typos.

  • omitempty actually omits zero-valued structs.

How to use it

github.com/koki/json is a drop-in replacement for encoding/json. The decoder implementation is different, but the library API remains unchanged. Use this package's json.Unmarshal if you want paths for your decoder errors. Use json.Marshal if you want to omit zero-valued structs.

// Deserialize
foo := Foo{}
err := json.Unmarshal(data, &foo)
...

// Serialize
bar := Bar{}
data, err := json.Marshal(bar)
...

github.com/koki/json/jsonutil is a brand-new package. Use jsonutil.ExtraneousFieldPaths to get a list of paths that weren't decoded into your Go object. i.e. potential typos.

// 1. Parse.
obj := make(map[string]interface{})
parsedObj := Foo{}
err := json.Unmarshal(data, &obj)
...
err = jsonutil.UnmarshalMap(obj, &parsedObj)
...

// 2. Check for unparsed fields--potential typos.
extraneousPaths, err := jsonutil.ExtraneousFieldPaths(obj, parsedObj)
...
if len(extraneousPaths) > 0 {
    return nil, &jsonutil.ExtraneousFieldsError{Paths: extraneousPaths}
}
...

About

Fork of golang's encoding/json: now with more validation and error context

Topics

golangjsonpath-validationtype-validation

Resources

Readme
BSD-3-Clause license
Activity
Custom properties

Stars

34 stars

Watchers

2 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.