jsonx

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2025 License: MIT Imports: 2 Imported by: 1

README

jsonx

A high-performance JSON serialization and deserialization library built on top of jsoniter, offering efficient and flexible JSON handling in Go.

Installation

go get github.com/GokselKUCUKSAHIN/jsonx

Usage

JSON Serialization and Deserialization
import "github.com/GokselKUCUKSAHIN/jsonx"

// Struct to be serialized
type User struct {
    Name  string `json:"name"`
    Email string `json:"email"`
}

user := User{Name: "John Doe", Email: "john@example.com"}

// Marshal to JSON
jsonData, err := jsonx.Marshal(user)
if err != nil {
    log.Fatal(err)
}

// Unmarshal from JSON
var parsedUser User
if err := jsonx.Unmarshal(jsonData, &parsedUser); err != nil {
    log.Fatal(err)
}
Casting Helpers
// Cast JSON response directly into a struct
rawData, err := fetchData()
user, err := jsonx.Cast[User](rawData, err)
if err != nil {
    log.Fatal(err)
}

// Cast JSON response into a slice of structs
rawList, err := fetchList()
users, err := jsonx.CastSlice[User](rawList, err)
if err != nil {
	log.Fatal(err)
}

Features

  • Fast JSON encoding/decoding powered by jsoniter
  • Convenient casting functions for structured data
  • Minimal performance overhead with efficient memory usage

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cast

func Cast[Model any](buf []byte, err error) (*Model, error)

func CastSlice

func CastSlice[Model any](buff []byte, err error) ([]Model, error)

func Marshal

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

func MarshalString

func MarshalString(val any) (string, error)

func Unmarshal

func Unmarshal(buf []byte, val any) error

func UnmarshalString

func UnmarshalString(buf string, val any) error

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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