jsonpath

package module
v0.0.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 15, 2022 License: MIT Imports: 4 Imported by: 1

README

Build Status Goreport License MIT

jsonpath - Json generation by dot notation

This library is very close to mongodb's dot notation with a bit of extensions.

Supported syntaxes

Standard dot notation

input hash value output json result
{"0.value":"100"} [{"value":"100"}]
{"1.value":"100"} [null, {"value":"100"}]
{"value":"100"} {"value":"100"}
{"value.1":"100"} {"value":[null, "100"]}
{"v.0.k":"100"} {"v":[{"k":100}]}

Extended

input hash value output json result
{"v.num()":"1.0"} {"v":1.0}
{"v.bool()":"true"} {"v":true}

Benchmarks

Run benchmarks

go test -bench=.

Results

v0.0.3

BenchmarkComplexJSONPathArray-8             	  100000	     12480 ns/op
BenchmarkSimpleJSONPathArrayWithNum-8       	  500000	      2654 ns/op
BenchmarkSimpleJSONPathArrayWithBool-8      	 1000000	      2319 ns/op
BenchmarkSimpleJSONPathArrayInsideArray-8   	  500000	      3066 ns/op
BenchmarkSimpleJSONPathArrays-8             	  500000	      2636 ns/op
BenchmarkSimpleJSONPathSimple-8             	 1000000	      1626 ns/op
BenchmarkJSONNative-8                       	 2000000	       959 ns/op

Installation

go get github.com/cthulhu/jsonpath

Usage

in := map[string]string{"0.value": "100.00"}
jsobBytes := jsonpath.Marshal(in)

For more examples check jsonpath_test.go file

LICENSE

See LICENSE file

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(keysAndValues map[string]string) ([]byte, error)

Marshal returns the JSON encoding of keysAndValues. Returns marshaled []byte and error in case if it can't be marshaled

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL