mirror of
https://github.com/gin-gonic/gin.git
synced 2026-04-30 07:38:15 +08:00
JSON Iterator Example
This example demonstrates how to integrate json-iterator/go with Gin to replace the default encoding/json for better performance.
How it works
Gin supports custom JSON serialization and deserialization logic via the json.API variable. By implementing the json.Core interface (which includes Marshal, Unmarshal, NewEncoder, NewDecoder etc.), we can swap out the underlying JSON engine.
Usage
- Define your custom configuration using
jsoniter.Config. - Implement the
json.Coreinterface wrappers. - Assign your custom implementation to
json.APIbefore creating the Gin engine.
Run the example
go run main.go
Test it:
curl http://localhost:8080/ping
# Output: {"message":"pong"}