Giter Site home page Giter Site logo

jsonerrors's Introduction

Go JSON Parsers: Errors

Go Version: go1.10

Test: Unknown object property.

Body:

{"cat": "Sammy", "dog": "Loki"}

Target:

struct { Cat string "json:\"cat\"" }
  • pkg encoding/json (stdlib)

    • json.Unmarshal

      Err: <nil>

       (interface {}) <nil>
    • json.Decoder.DisallowUnknownFields

      Err: json: unknown field "dog"

       (*errors.errorString)(0xc4200a4c30)({
         s: (string) (len=25) "json: unknown field \"dog\""
       })
  • pkg github.com/json-iterator/go

    • jsoniter.ConfigCompatibleWithStandardLibrary

      Err: <nil>

       (interface {}) <nil>
  • pkg github.com/koki/json

    • json.Unmarshal

      Err: <nil>

       (interface {}) <nil>
    • json.UnmarshalMap

      Err: <nil>

       (interface {}) <nil>
    • json.UnmarshalMap + jsonutil.ExtraneousFieldPaths

      Err: extraneous fields (typos?) at paths: $.dog

       (*jsonutil.ExtraneousFieldsError)(0xc4200bae80)({
         Paths: ([][]string) (len=1 cap=1) {
           ([]string) (len=1 cap=1) {
             (string) (len=3) "dog"
           }
         }
       })

Test: Using a string instead of an object.

Body:

{"cat": "sammy"}

Target:

struct { Cat struct {} "json:\"cat\"" }
  • pkg encoding/json (stdlib)

    • json.Unmarshal

      Err: json: cannot unmarshal string into Go struct field .cat of type struct {}

       (*json.UnmarshalTypeError)(0xc4200be4b0)({
         Value: (string) (len=6) "string",
         Type: (*reflect.rtype)(0x120fb20)({
           size: (uintptr) <nil>,
           ptrdata: (uintptr) <nil>,
           hash: (uint32) 670477339,
           tflag: (reflect.tflag) 2,
           align: (uint8) 1,
           fieldAlign: (uint8) 1,
           kind: (uint8) 153,
           alg: (*reflect.typeAlg)(0x13bdd30)({
             hash: (func(unsafe.Pointer, uintptr) uintptr) 0x1001b60,
             equal: (func(unsafe.Pointer, unsafe.Pointer) bool) 0x1002360
           }),
           gcdata: (*uint8)(0x127a228)(1),
           str: (reflect.nameOff) 21559,
           ptrToThis: (reflect.typeOff) 118240
         }),
         Offset: (int64) 15,
         Struct: (string) "",
         Field: (string) (len=3) "cat"
       })
    • json.Decoder.DisallowUnknownFields

      Err: json: cannot unmarshal string into Go struct field .cat of type struct {}

       (*json.UnmarshalTypeError)(0xc4200be500)({
         Value: (string) (len=6) "string",
         Type: (*reflect.rtype)(0x120fb20)({
           size: (uintptr) <nil>,
           ptrdata: (uintptr) <nil>,
           hash: (uint32) 670477339,
           tflag: (reflect.tflag) 2,
           align: (uint8) 1,
           fieldAlign: (uint8) 1,
           kind: (uint8) 153,
           alg: (*reflect.typeAlg)(0x13bdd30)({
             hash: (func(unsafe.Pointer, uintptr) uintptr) 0x1001b60,
             equal: (func(unsafe.Pointer, unsafe.Pointer) bool) 0x1002360
           }),
           gcdata: (*uint8)(0x127a228)(1),
           str: (reflect.nameOff) 21559,
           ptrToThis: (reflect.typeOff) 118240
         }),
         Offset: (int64) 15,
         Struct: (string) "",
         Field: (string) (len=3) "cat"
       })
  • pkg github.com/json-iterator/go

    • jsoniter.ConfigCompatibleWithStandardLibrary

      Err: struct { Cat struct {} "json:\"cat\"" }.Cat: skipObjectDecoder: expect object or null, error found in #8 byte of ...|{"cat": "sammy"}|..., bigger context ...|{"cat": "sammy"}|...

       (*errors.errorString)(0xc4200a5180)({
         s: (string) (len=178) "struct { Cat struct {} \"json:\\\"cat\\\"\" }.Cat: skipObjectDecoder: expect object or null, error found in #8 byte of ...|{\"cat\": \"sammy\"}|..., bigger context ...|{\"cat\": \"sammy\"}|..."
       })
  • pkg github.com/koki/json

    • json.Unmarshal

      Err: $.cat: json: cannot unmarshal string into Go struct field .cat of type struct {}

       (*structurederrors.ErrorWithContext)(0xc4201381e0)({
         BaseError: (*json.UnmarshalTypeError)(0xc4200be550)({
           Value: (string) (len=6) "string",
           Type: (*reflect.rtype)(0x120fb20)({
             size: (uintptr) <nil>,
             ptrdata: (uintptr) <nil>,
             hash: (uint32) 670477339,
             tflag: (reflect.tflag) 2,
             align: (uint8) 1,
             fieldAlign: (uint8) 1,
             kind: (uint8) 153,
             alg: (*reflect.typeAlg)(0x13bdd30)({
               hash: (func(unsafe.Pointer, uintptr) uintptr) 0x1001b60,
               equal: (func(unsafe.Pointer, unsafe.Pointer) bool) 0x1002360
             }),
             gcdata: (*uint8)(0x127a228)(1),
             str: (reflect.nameOff) 21559,
             ptrToThis: (reflect.typeOff) 118240
           }),
           Offset: (int64) 15,
           Struct: (string) "",
           Field: (string) (len=3) "cat"
         }),
         Context: ([]string) (len=1 cap=1) {
           (string) (len=5) "$.cat"
         }
       })
    • json.UnmarshalMap

      Err: $.cat: json: cannot unmarshal string into Go struct field .cat of type struct {}

       (*structurederrors.ErrorWithContext)(0xc4201382d0)({
         BaseError: (*json.UnmarshalTypeError)(0xc4200be5a0)({
           Value: (string) (len=6) "string",
           Type: (*reflect.rtype)(0x120fb20)({
             size: (uintptr) <nil>,
             ptrdata: (uintptr) <nil>,
             hash: (uint32) 670477339,
             tflag: (reflect.tflag) 2,
             align: (uint8) 1,
             fieldAlign: (uint8) 1,
             kind: (uint8) 153,
             alg: (*reflect.typeAlg)(0x13bdd30)({
               hash: (func(unsafe.Pointer, uintptr) uintptr) 0x1001b60,
               equal: (func(unsafe.Pointer, unsafe.Pointer) bool) 0x1002360
             }),
             gcdata: (*uint8)(0x127a228)(1),
             str: (reflect.nameOff) 21559,
             ptrToThis: (reflect.typeOff) 118240
           }),
           Offset: (int64) 14,
           Struct: (string) "",
           Field: (string) (len=3) "cat"
         }),
         Context: ([]string) (len=1 cap=1) {
           (string) (len=5) "$.cat"
         }
       })
    • json.UnmarshalMap + jsonutil.ExtraneousFieldPaths

      Err: $.cat: json: cannot unmarshal string into Go struct field .cat of type struct {}

       (*structurederrors.ErrorWithContext)(0xc4201383c0)({
         BaseError: (*json.UnmarshalTypeError)(0xc4200be5f0)({
           Value: (string) (len=6) "string",
           Type: (*reflect.rtype)(0x120fb20)({
             size: (uintptr) <nil>,
             ptrdata: (uintptr) <nil>,
             hash: (uint32) 670477339,
             tflag: (reflect.tflag) 2,
             align: (uint8) 1,
             fieldAlign: (uint8) 1,
             kind: (uint8) 153,
             alg: (*reflect.typeAlg)(0x13bdd30)({
               hash: (func(unsafe.Pointer, uintptr) uintptr) 0x1001b60,
               equal: (func(unsafe.Pointer, unsafe.Pointer) bool) 0x1002360
             }),
             gcdata: (*uint8)(0x127a228)(1),
             str: (reflect.nameOff) 21559,
             ptrToThis: (reflect.typeOff) 118240
           }),
           Offset: (int64) 14,
           Struct: (string) "",
           Field: (string) (len=3) "cat"
         }),
         Context: ([]string) (len=1 cap=1) {
           (string) (len=5) "$.cat"
         }
       })

jsonerrors's People

Watchers

Paul Scott avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.