yq/pkg/yqlib/decoder_json.go

37 lines
574 B
Go
Raw Normal View History

//go:build !yq_nojson
2022-07-27 02:26:22 +00:00
package yqlib
import (
"io"
"github.com/goccy/go-json"
)
type jsonDecoder struct {
decoder json.Decoder
}
func NewJSONDecoder() Decoder {
return &jsonDecoder{}
}
func (dec *jsonDecoder) Init(reader io.Reader) error {
2022-07-27 02:26:22 +00:00
dec.decoder = *json.NewDecoder(reader)
return nil
2022-07-27 02:26:22 +00:00
}
func (dec *jsonDecoder) Decode() (*CandidateNode, error) {
2022-07-27 02:26:22 +00:00
2023-04-13 05:40:41 +00:00
var dataBucket CandidateNode
2022-07-27 02:26:22 +00:00
err := dec.decoder.Decode(&dataBucket)
if err != nil {
return nil, err
2022-07-27 02:26:22 +00:00
}
return &CandidateNode{
2023-04-03 12:25:37 +00:00
Kind: DocumentNode,
2023-04-13 05:40:41 +00:00
Content: []*CandidateNode{&dataBucket},
}, nil
2022-07-27 02:26:22 +00:00
}