Skip to content

json: +-Inf and NaN #365

Closed
Closed
@holycheater

Description

@holycheater
  1. json encodes math.Inf and math.Nan (which is against json specification)
  2. it fails to decode it
  3. it isn't compatible with standard encoding/json which raises error
  4. it isn't compatible with json standard (https://www.json.org http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf)
    Quote:
Numeric values that cannot be represented as sequences of digits (such as Infinity and NaN) are not permitted

this piece of code does not work:

func main() {
	encVal := math.Inf(1)
	s, e := jsoniter.MarshalToString(encVal)
	log.Println(s, e)

	var dec float64
	err := jsoniter.UnmarshalFromString(s, &dec)
	log.Print(err)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions