tinyjson

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 1 Imported by: 0

README

TinyJSON

A lightweight JSON wrapper for Go that optimizes WebAssembly binary size. It automatically switches between the standard encoding/json for backends and the browser's native JSON API (via syscall/js) for WASM builds.

Usage

package main

import (
    "github.com/cdvelop/tinyjson"
)

func main() {
    tj := tinyjson.New()

    // Encode data to JSON
    data := map[string]string{"message": "Hello, World!"}
    jsonBytes, err := tj.Encode(data)
    if err != nil {
        panic(err)
    }
    println(string(jsonBytes)) // {"message":"Hello, World!"}

    // Decode JSON back to data
    var result map[string]string
    err = tj.Decode(jsonBytes, &result)
    if err != nil {
        panic(err)
    }
    println(result) // map[message:Hello, World!]
}

Benchmarks

Binary size comparison using TinyGo and Gzip compression:

Implementation Binary Size (WASM + Gzip)
TinyJSON 27.2 KB
encoding/json (stdlib) 119 KB

For build instructions and detailed benchmarking information, see benchmarks/README.md.

Screenshots

TinyJSON (27.2 KB): TinyJSON Benchmark

Standard Library JSON (119 KB): Stdlib JSON Benchmark

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TinyJSON

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

func New

func New() *TinyJSON

func (*TinyJSON) Decode

func (t *TinyJSON) Decode(data []byte, v any) error

func (*TinyJSON) Encode

func (t *TinyJSON) Encode(data any) ([]byte, error)

Directories

Path Synopsis
benchmarks
clients/stdlib command
web command

Jump to

Keyboard shortcuts

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