Skip to content

Goccy returns different error messages on unmarshal than standard json #274

Closed
@zeripath

Description

Goccy returns different error messages on unmarshal than standard json:

package main

import (
	stdjson "encoding/json"
	"fmt"
	"strings"

	goccy_json "github.com/goccy/go-json"
)

type Parent struct {
	Is bool `json:"is"`
}

func main() {
	p := Parent{Is: true}

	err := stdjson.Unmarshal([]byte("invalid json"), &p)
	fmt.Println("StdJSON:", err)

	err = goccy_json.Unmarshal([]byte("invalid json"), &p)
	fmt.Println("Goccy JSON:", err)

	err = stdjson.NewDecoder(strings.NewReader("invalid json")).Decode(&p)
	fmt.Println("StdJSON:", err)

	err = goccy_json.NewDecoder(strings.NewReader("invalid json")).Decode(&p)
	fmt.Println("Goccy JSON:", err)
}

This returns:

StdJSON: invalid character 'i' looking for beginning of value
Goccy JSON: not at beginning of value
StdJSON: invalid character 'i' looking for beginning of value
Goccy JSON: not at beginning of value

This makes goccy json not a complete drop in replacement.

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions