json

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package json provides encoding/json-compatible entry points.

This package is intended for low-friction migration from the standard library surface. For JSON5/JSONC features and rich diagnostics, use the root jsonkit package directly.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Compact

func Compact(dst *bytes.Buffer, src []byte) error

Compact mirrors encoding/json.Compact.

func HTMLEscape

func HTMLEscape(dst *bytes.Buffer, src []byte)

HTMLEscape mirrors encoding/json.HTMLEscape.

func Indent

func Indent(dst *bytes.Buffer, src []byte, prefix, indent string) error

Indent mirrors encoding/json.Indent.

func Marshal

func Marshal(v any) ([]byte, error)

Marshal mirrors encoding/json.Marshal.

Example
package main

import (
	"fmt"

	jsoncompat "github.com/forgemechanic/jsonkit/compat/json"
)

func main() {
	out, err := jsoncompat.Marshal(struct {
		ID int `json:"id"`
	}{ID: 9})

	fmt.Println(err == nil)
	fmt.Println(string(out))
}
Output:
true
{"id":9}

func MarshalIndent

func MarshalIndent(v any, prefix, indent string) ([]byte, error)

MarshalIndent mirrors encoding/json.MarshalIndent.

func Unmarshal

func Unmarshal(data []byte, v any) error

Unmarshal mirrors encoding/json.Unmarshal.

Example
package main

import (
	"fmt"

	jsoncompat "github.com/forgemechanic/jsonkit/compat/json"
)

func main() {
	var dst struct {
		Name string `json:"name"`
	}
	err := jsoncompat.Unmarshal([]byte(`{"name":"jsonkit"}`), &dst)

	fmt.Println(dst.Name)
	fmt.Println(err == nil)
}
Output:
jsonkit
true

func Valid

func Valid(data []byte) bool

Valid mirrors encoding/json.Valid.

Types

type Decoder

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

Decoder mirrors encoding/json.Decoder behavior.

Example
package main

import (
	"fmt"
	"strings"

	jsoncompat "github.com/forgemechanic/jsonkit/compat/json"
)

func main() {
	dec := jsoncompat.NewDecoder(strings.NewReader(`{"id":7}`))
	var dst map[string]any
	err := dec.Decode(&dst)

	fmt.Println(err == nil)
	fmt.Println(dst["id"])
}
Output:
true
7

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder mirrors encoding/json.NewDecoder.

func (*Decoder) Buffered

func (d *Decoder) Buffered() io.Reader

Buffered mirrors encoding/json.Decoder.Buffered.

func (*Decoder) Decode

func (d *Decoder) Decode(v any) error

Decode mirrors encoding/json.Decoder.Decode.

func (*Decoder) DisallowUnknownFields

func (d *Decoder) DisallowUnknownFields()

DisallowUnknownFields mirrors encoding/json.Decoder.DisallowUnknownFields.

func (*Decoder) InputOffset

func (d *Decoder) InputOffset() int64

InputOffset mirrors encoding/json.Decoder.InputOffset.

func (*Decoder) More

func (d *Decoder) More() bool

More mirrors encoding/json.Decoder.More.

func (*Decoder) Token

func (d *Decoder) Token() (Token, error)

Token mirrors encoding/json.Decoder.Token.

func (*Decoder) UseNumber

func (d *Decoder) UseNumber()

UseNumber mirrors encoding/json.Decoder.UseNumber.

type Delim

type Delim = stdjson.Delim

type Encoder

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

Encoder mirrors encoding/json.Encoder behavior.

Example
package main

import (
	"bytes"
	"fmt"

	jsoncompat "github.com/forgemechanic/jsonkit/compat/json"
)

func main() {
	var buf bytes.Buffer
	enc := jsoncompat.NewEncoder(&buf)
	err := enc.Encode(map[string]int{"id": 5})

	fmt.Println(err == nil)
	fmt.Printf("%q\n", buf.String())
}
Output:
true
"{\"id\":5}\n"

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder mirrors encoding/json.NewEncoder.

func (*Encoder) Encode

func (e *Encoder) Encode(v any) error

Encode mirrors encoding/json.Encoder.Encode.

func (*Encoder) SetEscapeHTML

func (e *Encoder) SetEscapeHTML(on bool)

SetEscapeHTML mirrors encoding/json.Encoder.SetEscapeHTML.

func (*Encoder) SetIndent

func (e *Encoder) SetIndent(prefix, indent string)

SetIndent mirrors encoding/json.Encoder.SetIndent.

type InvalidUnmarshalError

type InvalidUnmarshalError = stdjson.InvalidUnmarshalError

type Marshaler

type Marshaler = stdjson.Marshaler

type MarshalerError

type MarshalerError = stdjson.MarshalerError

type Number

type Number = stdjson.Number

Common encoding/json surface aliases for compatibility.

type RawMessage

type RawMessage = stdjson.RawMessage

type SyntaxError

type SyntaxError = stdjson.SyntaxError

type Token

type Token = stdjson.Token

type UnmarshalTypeError

type UnmarshalTypeError = stdjson.UnmarshalTypeError

type Unmarshaler

type Unmarshaler = stdjson.Unmarshaler

type UnsupportedTypeError

type UnsupportedTypeError = stdjson.UnsupportedTypeError

type UnsupportedValueError

type UnsupportedValueError = stdjson.UnsupportedValueError

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL