Documentation ¶
Overview ¶
Package weaktyping is a go package for unmashaling weakly-typed-JSON.
Here is an example of weakly-typed-JSON.
{ "integer1": "123", "integer2": 456 }
If you want to umarshal this JSON into following Go struct, "encoding/json".Unmarshal will fail.
ptr := &struct { Integer1 int Integer2 int }() json.Unmarshal(in, ptr) // will fail
You can use weaktyping.Int instead of int for unmarshaling this JSON.
ptr := &struct { Integer1 weaktyping.Int Integer2 weaktyping.Int }() json.Unmarshal(in, ptr) // will succeed
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bool ¶
type Bool bool
Bool is weak typed bool. false, 0, "", and null are treated as false, others are true. This behavior is same as JavaScriptBool.
func (*Bool) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Bool) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Float32 ¶
type Float32 float32
Float32 is weak typed float32.
func (*Float32) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Float32) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Float64 ¶
type Float64 float64
Float64 is weak typed float64.
func (*Float64) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Float64) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Int ¶
type Int int
Int is weak typed int.
func (*Int) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
Example ¶
ptr := &struct { Foo weaktyping.Int `json:"foo"` }{} if err := json.Unmarshal([]byte(`{"foo":123}`), ptr); err != nil { log.Fatal(err) } fmt.Println("Foo:", ptr.Foo) if err := json.Unmarshal([]byte(`{"foo":"456"}`), ptr); err != nil { log.Fatal(err) } fmt.Println("Foo:", ptr.Foo)
Output: Foo: 123 Foo: 456
func (*Int) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Int16 ¶
type Int16 int16
Int16 is weak typed int16.
func (*Int16) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Int16) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Int32 ¶
type Int32 int32
Int32 is weak typed int32.
func (*Int32) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Int32) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Int64 ¶
type Int64 int64
Int64 is weak typed int64.
func (*Int64) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Int64) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Int8 ¶
type Int8 int8
Int8 is weak typed int8.
func (*Int8) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Int8) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type JavaScriptBool ¶
type JavaScriptBool bool
JavaScriptBool is weak typed bool. false, 0, "", and null are treated as false, others are true.
func PtrJavaScriptBool ¶
func PtrJavaScriptBool(v JavaScriptBool) *JavaScriptBool
PtrJavaScriptBool returns the pointer of v.
func (*JavaScriptBool) UnmarshalJSON ¶
func (v *JavaScriptBool) UnmarshalJSON(data []byte) error
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*JavaScriptBool) UnmarshalText ¶
func (v *JavaScriptBool) UnmarshalText(data []byte) error
UnmarshalText implements "encoding".TextUnmarshaler.
type PHPBool ¶
type PHPBool bool
PHPBool is weak typed bool. false, 0, "", [], and null are treated as false, others are true.
func (*PHPBool) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*PHPBool) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type PerlBool ¶
type PerlBool bool
PerlBool is weak typed bool. false, 0, "0", "", and null are treated as false, others are true.
func (*PerlBool) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*PerlBool) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type PythonBool ¶
type PythonBool bool
PythonBool is weak typed bool. false, 0, "", [], {}, and null are treated as false, others are true.
func PtrPythonBool ¶
func PtrPythonBool(v PythonBool) *PythonBool
PtrPythonBool returns the pointer of v.
func (*PythonBool) UnmarshalJSON ¶
func (v *PythonBool) UnmarshalJSON(data []byte) error
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*PythonBool) UnmarshalText ¶
func (v *PythonBool) UnmarshalText(data []byte) error
UnmarshalText implements "encoding".TextUnmarshaler.
type RubyBool ¶
type RubyBool bool
RubyBool is weak typed bool. false and null are treated as false, others are true.
func (*RubyBool) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*RubyBool) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type String ¶
type String string
String is weak typed bool.
func (*String) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*String) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Uint ¶
type Uint uint
Uint is weak typed uint.
func (*Uint) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Uint) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Uint16 ¶
type Uint16 uint16
Uint16 is weak typed uint16.
func (*Uint16) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Uint16) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Uint32 ¶
type Uint32 uint32
Uint32 is weak typed uint32.
func (*Uint32) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Uint32) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Uint64 ¶
type Uint64 uint64
Uint64 is weak typed uint64.
func (*Uint64) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Uint64) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.
type Uint8 ¶
type Uint8 uint8
Uint8 is weak typed uint8.
func (*Uint8) UnmarshalJSON ¶
UnmarshalJSON implements "encoding/json".Unmarshaler.
func (*Uint8) UnmarshalText ¶
UnmarshalText implements "encoding".TextUnmarshaler.