Back to godoc.org
github.com/akshaybharambe14/go-jsonc

Package jsonc

v1.0.0
Latest Go to latest
Published: May 8, 2020 | License: MIT | Module: github.com/akshaybharambe14/go-jsonc

Index

Package Files

Variables

var (
	ErrUnexpectedEndOfComment = errors.New("unexpected end of comment")
)

func DecodeBytes

func DecodeBytes(p []byte) (int, error)

DecodeBytes decodes passed commented json byte slice to normal json. It modifies the passed slice. The passed slice must be refferred till returned count, if there is no error.

The error doesn't include errors related to invalid json. If not nil, it must be ErrUnexpectedEndOfComment.

The returned json must be checked for validity.

func DecodeString

func DecodeString(s string) (string, error)

DecodeString decodes passed commented json to normal json. It uses "unsafe" way to convert a byte slice to result string. This saves allocations and improves performance is case of large json.

The error doesn't include errors related to invalid json. If not nil, it must be ErrUnexpectedEndOfComment.

The returned json must be checked for validity.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder represents a .jsonc decoder. It implements io.Reader.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new Decoder wrapping the provided io.Reader.

func (*Decoder) Read

func (d *Decoder) Read(p []byte) (int, error)

Read reads from underlying reader and processes the stream to omit comments. A single read doesn't guaranttee a valid JSON. Depends on length of passed slice.

Produces ErrUnexpectedEndOfComment for incomplete comments else if not nil, then it is an error from underlying reader.

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier