Megajson high-performance JSON serialization and deserialization tool

Source: Internet
Author: User
This is a created article in which the information may have evolved or changed.

Go comes with a encoding/json that supports serialization and deserialization of JSON, however it is based on reflection and has several drawbacks:

  • Reflection is synonymous with poor performance and cannot be optimized at compile time.
  • Only the public field is available, and the reflection library can only reflect the exposed fields, which means that you cannot json convert the private field.

Https://github.com/benbjohnson/megajson is optimized for this problem, which is a code generation tool that produces custom serial numbers and deserialization code for your own type entities by using the Go/parser and go/ast packages. The serial number and deserialization here know your data type, so there is no reflection and then the problem is solved.

With the test, Go 1.2, Megajson twice times better performance than the Encoding/json package.

Installation method:

$ go Get Github.com/benbjohnson/megajson

Use:

Run the Megajson command directly, which will produce the serialized and deserialized files you need:

$ Megajson Mypkg/my_file.go

This will result in 2 files:

mypkg/my_file_encoder.gomypkg/my_file_decoder.go

It is relatively simple to use, as follows:

ERR: = Newmystructencoder (writer). Encode (val) Err: = Newmystructdecoder (reader). Decode (&val)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.