ugorji / go

idiomatic codec and rpc lib for msgpack, cbor, json, etc. msgpack.org[Go]
MIT License
1.86k stars 295 forks source link

appendStringAsBytes with null issue #180

Closed seanchann closed 8 years ago

seanchann commented 8 years ago

hi: if have json:

   {
       "test":{
              "key1": null,
              "key2": null,
              "key3":"test3"
        }
   }

decode will be throw error : " json: expect char '\\"' but got char 'n'"

I think if have null may be give a empty string to filed?

ugorji commented 8 years ago

Please attach a reproducer that can be run via "go run repro.go" or "go test".

ugorji commented 8 years ago

I just tested with the code below, and it works.

package main

import ( "fmt" "github.com/ugorji/go/codec" )

func main() { var a interface{} var ss = { "test":{ "key1": null, "key2": null, "key3":"test3" } }

var s = []byte(ss)
var h codec.JsonHandle
codec.NewDecoderBytes(s, &h).Decode(&a)
fmt.Printf("a is now: %v of type: %T and is nil: %v\n", a, a, a == nil)

}

Output:

a is now: map[test:map[key1: key2: key3:test3]] of type: map[interface {}]interface {} and is nil: false

seanchann commented 8 years ago

@ugorji sorry, will retry it!