Skip to content

chenwaichung/jsoniter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsoniter (temporary compatibility fork)

This repository provides a temporary drop-in replacement for github.com/json-iterator/go to help projects migrate to newer Go versions when the upstream library is no longer maintained.

Goals

  • Keep common API compatibility for migration scenarios.
  • Support jsoniter.Marshal and jsoniter.Unmarshal.
  • Support jsoniter.ConfigCompatibleWithStandardLibrary.
  • Support extra.RegisterFuzzyDecoders().

Install

In your project go.mod, point imports to this module path:

require github.com/chenwaichung/jsoniter v0.0.0

Then use replace to your local/internal fork if needed:

replace github.com/chenwaichung/jsoniter => /path/to/this/repo

Usage

Basic marshal/unmarshal

package main

import (
	"fmt"

	jsoniter "github.com/chenwaichung/jsoniter"
)

type User struct {
	Name string `json:"name"`
	Age  int    `json:"age"`
}

func main() {
	raw, _ := jsoniter.Marshal(User{Name: "alice", Age: 18})

	var out User
	_ = jsoniter.Unmarshal(raw, &out)

	fmt.Println(string(raw), out.Name, out.Age)
}

Compatible-with-standard-library config

package main

import (
	"fmt"

	jsoniter "github.com/chenwaichung/jsoniter"
)

func main() {
	data, _ := jsoniter.ConfigCompatibleWithStandardLibrary.Marshal(map[string]string{
		"html": "<b>",
	})
	fmt.Println(string(data)) // {"html":"\u003cb\u003e"}
}

Fuzzy decoders

package main

import (
	"fmt"

	jsoniter "github.com/chenwaichung/jsoniter"
	"github.com/chenwaichung/jsoniter/extra"
)

type Payload struct {
	ID    int     `json:"id"`
	Score float64 `json:"score"`
	OK    bool    `json:"ok"`
}

func main() {
	extra.RegisterFuzzyDecoders()

	var p Payload
	_ = jsoniter.Unmarshal([]byte(`{"id":"42","score":"9.5","ok":"1"}`), &p)
	fmt.Println(p.ID, p.Score, p.OK)
}

Notes

  • This is a migration-focused compatibility layer, not a full re-implementation of every upstream feature.
  • Please add tests around your project's critical serialization paths during migration.

Acknowledgements

Special thanks to the original github.com/json-iterator/go project and its contributors. This temporary compatibility fork is built to ease migration while preserving familiar APIs.

License

MIT. See LICENSE.

About

This is a migration-focused compatibility layer, not a full re-implementation of every upstream feature.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages