• This repository has been archived on 15/Dec/2019
  • Stars
    star
    466
  • Rank 94,105 (Top 2 %)
  • Language
    Go
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A JSON parser generator for high performance encoding and decoding in Go.

megajson status

High performance Go JSON encoder and decoder.

Notice: This tool is unmaintained. Please use ffjson instead.

Overview

Go's builtin JSON support works great to provide simple, runtime JSON encoding and decoding. However, it's based on reflection so it has a few drawbacks:

  • Performance - The reflection library is slow and isn't optimized by the compiler at compile time.

  • Public Fields Only - The reflection library can only reflect on exported fields. That means that you can't marshal private fields to JSON.

Megajson is built to get around some of these limitations. It's a code generation tool that uses the go/parser and go/ast packages to write custom encoders and decoders for your types. These encoders and decoders know your types so the reflection package is not necessary.

Performance

Megajson encodes and decodes at approximately two times the speed of the encoding/json package using the built-in encoding/json test data in Go 1.2. This is just a benchmark though. Your mileage may vary.

Please test megajson encoders using real data for actual results. This library is primarily focused on performance so performance improvement pull requests are very welcome.

Installation

Installing megajson is easy. Simply go get from the command line:

$ go get github.com/benbjohnson/megajson

And you're ready to go.

Usage

Running megajson is simple. Just provide the files or directories that you want to generate encoders and decoders for:

$ megajson mypkg/my_file.go

Two new files will be generated:

mypkg/my_file_encoder.go
mypkg/my_file_decoder.go

They live in the same package as your my_file.go code so they're ready to go.

Once your encoders and decoders are generated, you can use them just like the json.Encoder and json.Decoder except they're named after your types. For a struct type inside my_file.go called MyStruct, the generated code can be used like this:

err := NewMyStructEncoder(writer).Encode(val)
err := NewMyStructDecoder(reader).Decode(&val)

Supported Types

The following struct field types are supported:

  • string
  • int, int64
  • uint, uint64
  • float32, float64
  • bool
  • Pointers to structs which have been megajsonified.
  • Arrays of pointers to structs which have megajsonified.

If you have a type that you would like to see supported, please add an issue to the GitHub page.

More Repositories

1

litestream

Streaming replication for SQLite.
Go
10,958
star
2

thesecretlivesofdata

Understanding what your bits do when you're not looking.
JavaScript
3,440
star
3

wtf

WTF Dial is an example web application written in Go.
Go
1,682
star
4

postlite

Postgres wire compatible SQLite proxy.
Go
1,216
star
5

immutable

Immutable collections for Go
Go
713
star
6

clock

Clock is a small library for mocking time in Go.
Go
677
star
7

ego

An ERB-style templating language for Go.
Go
581
star
8

testing

A small collection of functions for Go testing.
Go
529
star
9

hashfs

Implementation of io/fs.FS that appends SHA256 hashes to filenames to allow for aggressive HTTP caching.
Go
358
star
10

sql-parser

Toy SQL parser example for Gopher Academy
Go
330
star
11

genesis

A simple tool for embedding assets in a Go binary.
Go
299
star
12

phantomjs

Go client for PhantomJS.
Go
293
star
13

jmphash

Implementation of the Jump Consistent Hash algorithm in Go.
Go
154
star
14

scuttlebutt

A daemon for tracking and tweeting trending Github repositories by language.
Go
151
star
15

llvm-c-kaleidoscope

An implementation of the Kaleidoscope language using Flex, Bison & the LLVM-C bindings.
C
129
star
16

playback.js

A library for dynamic timeline playback.
JavaScript
118
star
17

litestream-docker-example

An example of using Litestream within a Docker container.
Go
97
star
18

litestream-s6-example

Example repository for building a multi-process Docker container.
Dockerfile
87
star
19

tmpl

Command line interface to Go's text/template library.
Go
84
star
20

css

W3C-compliant CSS3 parser and scanner
Go
83
star
21

grapevine

Trending topics for stuff you care about
Ruby
80
star
22

slowweb

An HTTP request governor
Ruby
75
star
23

litestream-read-replica-demo

A demo application for running live read replication on fly.io with Litestream
Go
69
star
24

ghfs

FUSE Filesystem for the GitHub API
Go
61
star
25

agency

A fast user agent string parser for Go.
Go
60
star
26

litestream-library-example

Example repository for embedding Litestream in a Go application.
Go
56
star
27

litestream-read-replica-example

An example of using Litestream's live read replication feature.
Go
52
star
28

melomel

External ActionScript Interface.
ActionScript
42
star
29

litestream.io

SCSS
40
star
30

pprofdump

A simple utility for collecting net/http/pprof profiles.
Go
28
star
31

peapod

A personal podcast service.
Go
26
star
32

application-development-using-boltdb

Repository for my "Application Development Using BoltDB" talk
Go
26
star
33

sieve

A command line utility for graphing piped data.
Go
23
star
34

production-sqlite-go

Companion repository for GopherCon presentation on "Production Applications Using SQLite & Go"
Go
23
star
35

goo

Thin wrapper for the Go toolchain.
Go
20
star
36

burger-stack

Presentation for "The Burger Stack"
19
star
37

structuring-applications-for-growth

GopherCon 2016 presentation for "Structuring Applications for Growth"
18
star
38

stack

Go debug/stack utility functions.
Go
18
star
39

myapp

An simple application with an HTTP server & SQLite database.
Go
14
star
40

glee

Incomplete Go port of the KLEE SymEx system.
Go
14
star
41

melomel.rb

An external interface to Flash from Ruby.
Ruby
13
star
42

raft.js

An experimental Raft implementation in Javascript.
13
star
43

vex

Variable-length, lexicographically-sortable hex format for uint64 values.
Go
13
star
44

gha

SQLite load testing application using GitHub Archive data.
Go
13
star
45

writing-a-distributed-systems-library

Companion code for the Gopher Academy blog post.
Go
11
star
46

roommate

A conference room scheduling application.
Go
10
star
47

tiny-ego

A toy application showcasing ego templates & components.
Go
10
star
48

boxer

A little app that boxes my time.
Go
10
star
49

bootstrap-ego

An ego template component library for Bootstrap 4.
Go
10
star
50

seppuku

To be executed upon implementation of generics in Go.
Go
10
star
51

syncutil

A collection of utility functions for Go synchronization.
Go
9
star
52

gist

Gist hosting and embedding.
Go
8
star
53

melomel-examples

Examples of using Melomel.
Ruby
8
star
54

describe.today

A web site to describe today.
JavaScript
7
star
55

minipack

A lightweight C MessagePack parser.
C
7
star
56

skybox

An open source funnel analysis application.
Go
7
star
57

go-raft-runner

A test runner application for the go-raft library.
Go
6
star
58

http-wiretap

It's like Charles Proxy for your Rubies!
Ruby
5
star
59

sqlite-bench

Miscellaneous Go/SQLite benchmarks
Go
5
star
60

mincore

Example usage for using mincore() in Go.
Go
5
star
61

miniviz

A simplified interface to GraphViz for laying out clusters, nodes and edges.
Ruby
5
star
62

graphviz-as3

An interface to the graphviz CLI using Adobe AIR.
ActionScript
5
star
63

edb

A simple database for tracking events.
Go
5
star
64

rationl

Online journal for tracking experiments.
Go
4
star
65

hackerbeeper

A dumb utility for playing generated notes when you type.
Go
4
star
66

opus

Command line utility for printing columnized code.
4
star
67

mockdown.as

A Markdown-inspired Mockup Language
ActionScript
4
star
68

serialkiller

ActionScript JSON & XML serialization library
ActionScript
4
star
69

whodump

A command line interface for checking domain name availability.
Ruby
4
star
70

tsld.js

Core library for "The Secret Lives of Data" project.
JavaScript
3
star
71

bandicoot

A crash reporter library for C applications.
C
3
star
72

skydb.io

The Official Sky Web Site
CSS
2
star
73

chatter

Demo application using Server Side Events (SSE) and written in Go.
Go
2
star
74

cine

A movie search application.
Go
2
star
75

authoritarian

Command line utility for authorizing Twitter users to an application.
2
star
76

constdump

Utility for printing a list of package-level constants.
Go
2
star
77

matlock

Simple name extraction utility.
Ruby
2
star
78

d3.jquery.js

A collection of D3.js charts made available as jQuery plugins.
JavaScript
1
star
79

mockdown.rb

Mockups for hackers
Ruby
1
star
80

landmarkd

The Landmark Tracking Server.
Go
1
star
81

httpng

A local server for saving HTML elements as PNG files.
JavaScript
1
star
82

ldbchk

Runs concurrency tests against LevelDB & Levigo.
Go
1
star
83

timeshifter

A Ruby library for shifting time.
Ruby
1
star
84

whollydeliciousfoods.com

The home page for Wholly Delicious Foods.
JavaScript
1
star
85

homebrew-litestream

Homebrew tap for litestream.
Ruby
1
star
86

bench-c

A small collection of benchmarks for the C programming language.
C
1
star
87

unistat

A utility for calculating simple statistics on unicode characters.
Go
1
star
88

gitcoin

Turing gitcoin repository
Go
1
star
89

termgraf

Terminal chronograf
Go
1
star
90

locald

A simple HTTP server for serving static files out of the current directory.
1
star
91

skylandlabs.github.com

Skyland Labs Blog
JavaScript
1
star
92

fql-editor

An editor for FQL queries.
ActionScript
1
star
93

tip.litestream.io

Mirror of litestream.io repository for latest changes.
HTML
1
star
94

prog

Go testing
Go
1
star
95

fslice

A small utility for extracting delimited sections of a file.
Go
1
star
96

ego-example

A simple ego templating example.
Go
1
star