Coder Social home page Coder Social logo

ojg's Introduction

{}j

Build StatusCoverage Status

OjG

Optimized JSON for Go is a high performance parser with a variety of additional JSON tools.

Features

  • Fast JSON parser. Check out the cmd/benchmarks app in this repo.
  • Full JSONPath implemenation that operates on simple types as well as structs.
  • Generic types. Not the proposed golang generics but type safe JSON elements.
  • Fast JSON validator (4 times faster with io.Reader).
  • Fast JSON writer with a sort option (1.6 times faster).
  • Simple data builders using a push and pop approach.
  • Object encoding and decoding using an approach similar to that used with Oj for Ruby.
  • Simple Encoding Notation, a lazy way to write JSON omitting commas and quotes.

Using

A basic Parse:

    obj, err := oj.ParseString(`{
        "a":[
            {"x":1,"y":2,"z":3},
            {"x":2,"y":4,"z":6}
        ]
    }`)

Using JSONPath expressions:

    x, err := jp.ParseString("a[?(@.x > 1)].y")
    ys := x.Get(obj)
    // returns [4]

The oj command (cmd/oj) which uses JSON path for filtering and extracting JSON elements. It also includes sorting, reformatting, and colorizing options.

$ oj -m "(@.name == 'Pete')" myfile.json

Installation

go get github.com/ohler55/ojg
go get github.com/ohler55/ojg/cmd/oj

or just import in your .go files.

import (
    "github.com/ohler55/ojg/alt"
    "github.com/ohler55/ojg/gen"
    "github.com/ohler55/ojg/jp"
    "github.com/ohler55/ojg/oj"
)

To build and install the oj application:

go install ./...

Benchmarks

Higher numbers in parenthesis are better.

Parse string/[]byte
 json.Unmarshal      7291 ns/op (1.00x)    4808 B/op (1.00x)      90 allocs/op (1.00x)
   oj.Parse          4775 ns/op (1.53x)    3984 B/op (1.21x)      86 allocs/op (1.05x)
  gen.Parse          4922 ns/op (1.48x)    3984 B/op (1.21x)      86 allocs/op (1.05x)
  sen.Parse          4713 ns/op (1.55x)    3984 B/op (1.21x)      86 allocs/op (1.05x)

Parse io.Reader
 json.Decode        52665 ns/op (1.00x)   32656 B/op (1.00x)     346 allocs/op (1.00x)
   oj.ParseReader   34116 ns/op (1.54x)   22913 B/op (1.43x)     434 allocs/op (0.80x)
  gen.ParseReder    33256 ns/op (1.58x)   22912 B/op (1.43x)     434 allocs/op (0.80x)
  sen.ParseReader   31718 ns/op (1.66x)   22832 B/op (1.43x)     428 allocs/op (0.81x)

to JSON
 json.Marshal        2746 ns/op (1.00x)     992 B/op (1.00x)      22 allocs/op (1.00x)
   oj.JSON            445 ns/op (6.17x)     131 B/op (7.57x)       4 allocs/op (5.50x)
   oj.Write           460 ns/op (5.97x)     131 B/op (7.57x)       4 allocs/op (5.50x)
  sen.String          445 ns/op (6.17x)     131 B/op (7.57x)       4 allocs/op (5.50x)

See all benchmarks

Releases

See CHANGELOG.md

Links

Links of Interest

Contributing

  • Provide a Pull Request off the develop branch.
  • Report a bug
  • Suggest an idea

ojg's People

Contributors

ohler55 avatar zuern avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.