Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

siathalysedI/ojg

 
 

Repository files navigation

{}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"
    "github.com/ohler55/ojg/sen"
)

To build and install the oj application:

go install ./...

Benchmarks

Higher numbers in parenthesis are better.

Parse string/[]byte
     json.Unmarshal     42144 ns/op   17982 B/op     336 allocs/op
       oj.Parse         24508 ns/op   18816 B/op     433 allocs/op
      gen.Parse         23930 ns/op   18815 B/op     433 allocs/op
      sen.Parse         25666 ns/op   18770 B/op     427 allocs/op

      gen █████████████████▌ 1.76
       oj █████████████████▏ 1.72
      sen ████████████████▍ 1.64
     json ▓▓▓▓▓▓▓▓▓▓ 1.00

Parse io.Reader
     json.Decode        52568 ns/op   32658 B/op     346 allocs/op
       oj.ParseReader   27764 ns/op   22911 B/op     434 allocs/op
      gen.ParseReder    27554 ns/op   22912 B/op     434 allocs/op
      sen.ParseReader   27654 ns/op   22912 B/op     434 allocs/op

      gen ███████████████████  1.91
      sen ███████████████████  1.90
       oj ██████████████████▉ 1.89
     json ▓▓▓▓▓▓▓▓▓▓ 1.00

to JSON with indentation
     json.Marshal       72788 ns/op   27326 B/op     352 allocs/op
       oj.JSON          12143 ns/op    4096 B/op       1 allocs/op
      sen.String        13615 ns/op    4096 B/op       1 allocs/op

       oj ███████████████████████████████████████████████████████████▉ 5.99
      sen █████████████████████████████████████████████████████▍ 5.35
     json ▓▓▓▓▓▓▓▓▓▓ 1.00

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

About

Optimized JSON for Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%