JSON Marshal Library

The JSON Marshal library and customization capabilities used by Hertz.

By default, Hertz integrates with and uses Sonic for serializing ctx.JSON interface and deserialization requests as defined in the binding package. Sonic is an ultra-high performance golang json library, also see Sonic README for details.

The following are requirements to enable Sonic:

  • Go 1.16 or above
  • Linux / darwin OS / Windows
  • Amd64 CPU with AVX instruction set

Sonic automatically fallback to golang’s encoding/json library when the above requirements have not been satisfied.

Bringing Your Own JSON Marshal Library

If Sonic does not meet your needs, you may provide your own implementation by calling ResetJSONMarshal for render and configure your own json unmarshal library for binding.

Conditional Compilation

Hertz supports conditional compilation to control the actual json library used, you can use -tags stdjson to choose to use the standard library.

go build -tags stdjson

If there are issues related to Sonic, please refer to Sonic README or propose an issue.


Last modified December 9, 2024 : Update prerequisite.md (#1178) (b5e2299)