This Go project demonstrates how to use the YYJSON library for high-performance JSON parsing. YYJSON is a fast and lightweight JSON library that provides a C API, which this project wraps with a Go interface.
- Unmarshals JSON data into a
map[string]interface{}using the YYJSON library. - Compares the result with the standard Go
json.Unmarshalfunction. - Provides a simple and efficient way to work with JSON data in Go.
- Go 1.16 or later
- The YYJSON library, which is included as a C header file in the project.
- Clone the repository:
git clone https://github.com/donge/go-yyjson.git
- Build and run the project:
go build -o yyjson-go
./yyjson-go
This shows that the YYJSON-based unmarshaling and the standard Go json.Unmarshal produce the same result.
The Unmarshal function in the project uses the YYJSON library to parse the input JSON data and convert it to a map[string]interface{}. The conversion is done by the convertCValueToMap and convertCValueToInterface functions, which recursively traverse the JSON structure and convert the YYJSON values to their Go equivalents.
The project also includes a simple benchmark to compare the performance of the YYJSON-based unmarshaling with the standard Go json.Unmarshal function.
This project only demonstrates the basic usage of the YYJSON library for unmarshaling JSON data. In a real-world application, you would need to handle more complex use cases, such as error handling, custom struct unmarshaling, and performance optimization.
If you find any issues or have suggestions for improvement, feel free to create a new issue or submit a pull request.