Help us shape the future of Go! Take the 2026 Go Developer Survey

json

package
v1.64.11 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 8 Imported by: 4

README

Package json

Пакет json расширяет библиотеку jsoniter с дополнительными возможностями:

  • Кастомное форматирование времени
  • Автоматическое преобразование имен полей camelCase, если не указан json тэг у структуры
  • Совместимость с API стандартной библиотеки encoding/json

Functions

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

Преобразовать переданный объект в массив байт json-формата.

Unmarshal(data []byte, ptr any) error

Преобразовать объект обратно из массива байт json-формата.

NewEncoder(w io.Writer) *jsoniter.Encoder

Создание потокового энкодера.

NewDecoder(r io.Reader) *jsoniter.Decoder

Создание потокового декодера.

EncodeInto(w io.Writer, value any) error

Оптимизированная запись в поток с автоматическим сбросом буфера

Usage

Default usage flow
package main

import (
	"log"
	"time"

	"github.com/txix-open/isp-kit/json"
)

type Message struct {
	Text      string
	CreatedAt time.Time
}

func main() {
	msg := Message{
		Text:      "hi x.x",
		CreatedAt: time.Now().UTC(),
	}
	/* data: {"text":"hi x.x","createdAt":"2009-11-10T23:00:00Z"} */
	data, err := json.Marshal(msg)
	if err != nil {
		log.Fatal(err)
	}

	var decoded Message
	err = json.Unmarshal(data, &decoded)
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Index

Constants

View Source
const (
	FullDateFormat = "2006-01-02T15:04:05.999Z07:00"
)

Variables

This section is empty.

Functions

func EncodeInto

func EncodeInto(w io.Writer, value any) error

func Marshal

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

func NewDecoder

func NewDecoder(r io.Reader) *jsoniter.Decoder

func NewEncoder

func NewEncoder(w io.Writer) *jsoniter.Encoder

func Unmarshal

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

Types

type RawMessage

type RawMessage = json.RawMessage

type TimeCodec

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

func NewTimeCodec

func NewTimeCodec(format string) *TimeCodec

func (*TimeCodec) Decode

func (codec *TimeCodec) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator)

func (*TimeCodec) Encode

func (codec *TimeCodec) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream)

func (*TimeCodec) IsEmpty

func (codec *TimeCodec) IsEmpty(ptr unsafe.Pointer) bool

Jump to

Keyboard shortcuts

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