Codec

codec/json

github.com/gin-gonic/gin/codec/json

import "github.com/gin-gonic/gin/codec/json"

Constants

Package indicates what library is being used for JSON encoding.

Source: codec/json/json.go:15

const Package = "encoding/json"

Variables

API the json codec in use.

Source: codec/json/api.go:10

var API Core

Types

type Core

Source: codec/json/api.go:13

Core the api for json codec.

type Core interface {
	Marshal(v any) ([]byte, error)
	Unmarshal(data []byte, v any) error
	MarshalIndent(v any, prefix, indent string) ([]byte, error)
	NewEncoder(writer io.Writer) Encoder
	NewDecoder(reader io.Reader) Decoder
}
Methods
  • Marshal func(v any) ([]byte, error)
  • Unmarshal func(data []byte, v any) error
  • MarshalIndent func(v any, prefix, indent string) ([]byte, error)
  • NewEncoder func(writer io.Writer) Encoder
  • NewDecoder func(reader io.Reader) Decoder

type Decoder

Source: codec/json/api.go:41

Decoder an interface reads and decodes JSON values from an input stream.

type Decoder interface {
	// UseNumber causes the Decoder to unmarshal a number into an any as a
	// Number instead of as a float64.
	UseNumber()

	// DisallowUnknownFields causes the Decoder to return an error when the destination
	// is a struct and the input contains object keys which do not match any
	// non-ignored, exported fields in the destination.
	DisallowUnknownFields()

	// Decode reads the next JSON-encoded value from its
	// input and stores it in the value pointed to by v.
	//
	// See the documentation for Unmarshal for details about
	// the conversion of JSON into a Go value.
	Decode(v any) error
}
Methods
  • UseNumber func()

    UseNumber causes the Decoder to unmarshal a number into an any as a Number instead of as a float64.

  • DisallowUnknownFields func()

    DisallowUnknownFields causes the Decoder to return an error when the destination is a struct and the input contains object keys which do not match any non-ignored, exported fields in the destination.

  • Decode func(v any) error

    Decode reads the next JSON-encoded value from its input and stores it in the value pointed to by v.

    See the documentation for Unmarshal for details about the conversion of JSON into a Go value.

type Encoder

Source: codec/json/api.go:22

Encoder an interface writes JSON values to an output stream.

type Encoder interface {
	// SetEscapeHTML specifies whether problematic HTML characters
	// should be escaped inside JSON quoted strings.
	// The default behavior is to escape &, <, and > to \u0026, \u003c, and \u003e
	// to avoid certain safety problems that can arise when embedding JSON in HTML.
	//
	// In non-HTML settings where the escaping interferes with the readability
	// of the output, SetEscapeHTML(false) disables this behavior.
	SetEscapeHTML(on bool)

	// Encode writes the JSON encoding of v to the stream,
	// followed by a newline character.
	//
	// See the documentation for Marshal for details about the
	// conversion of Go values to JSON.
	Encode(v any) error
}
Methods
  • SetEscapeHTML func(on bool)

    SetEscapeHTML specifies whether problematic HTML characters should be escaped inside JSON quoted strings. The default behavior is to escape &, <, and > to \u0026, \u003c, and \u003e to avoid certain safety problems that can arise when embedding JSON in HTML.

    In non-HTML settings where the escaping interferes with the readability of the output, SetEscapeHTML(false) disables this behavior.

  • Encode func(v any) error

    Encode writes the JSON encoding of v to the stream, followed by a newline character.

    See the documentation for Marshal for details about the conversion of Go values to JSON.