jl package - github.com/bayashi/go-jl - Go Packages

jl

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2023 License: MIT Imports: 6 Imported by: 0

README

go-jl

MIT License go-jl CI

Show the "JSON within JSON" log nicely

Usage

jl command recursively converts JSON within JSON into one JSON structure.

Simple case:

$ cat simple.json
{
    "foo": "{\"bar\":\"{\\\"baz\\\":123}\"}"
}

$ cat simple.json | jl -p
{
 "foo": {
  "bar": {
   "baz": 123
  }
 }
}

Most use cases:

$ cat log.json
{
    "message": "{\"level\":\"info\",\"ts\":1557004280.5372975,\"caller\":\"zap/server_interceptors.go:40\",\"msg\":\"finished unary call with code OK\",\"grpc.start_time\":\"2019-05-04T21:11:20Z\",\"system\":\"grpc\",\"span.kind\":\"server\",\"grpc.service\":\"FooService\",\"grpc.method\":\"GetBar\",\"grpc.code\":\"OK\",\"grpc.time_ms\":248.45199584960938}\n",
    "namespace": "foo-service",
    "podName": "foo-86495899d8-m2vfl",
    "containerName": "foo-service"
}

$ cat log.json | jl -p
{
    "containerName": "foo-service",
    "message": {
        "caller": "zap/server_interceptors.go:40",
        "grpc.code": "OK",
        "grpc.method": "GetBar",
        "grpc.service": "FooService",
        "grpc.start_time": "2019-05-04T21:11:20Z",
        "grpc.time_ms": 248.45199584960938,
        "level": "info",
        "msg": "finished unary call with code OK",
        "span.kind": "server",
        "system": "grpc",
        "ts": 1557004280.5372975
    },
    "namespace": "foo-service",
    "podName": "foo-86495899d8-m2vfl"
}

Full options:

Options:
  -h, --help         Display help (This message) and exit
  -p, --prettify     Prettify the JSON
  -e, --show-error   Set this option to show errors, muted by default
  -v, --version      Display version and build info and exit

Installation

homebrew install

If you are using Mac:

brew tap bayashi/go-jl
brew install bayashi/go-jl/go-jl
binary install

Download binary from here: https://github.com/bayashi/go-jl/releases

go install

If you have golang envvironment:

go install github.com/bayashi/go-jl/cmd/jl@latest

License

MIT License

Author

Dai Okabayashi: https://github.com/bayashi

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Process

func Process(o *Options, origJson []byte) []byte

Process tries to convert "JSON within JSON" line to JUST Nested JSON line. If there would be an error, return original JSON straightfarward.

Example

Example test for error output

Process(&Options{ShowErr: true}, []byte("{"))
Output:
unexpected end of JSON input

Types

type Flatter

type Flatter struct {
	// contains filtered or unexported fields
}

Flatter stores path data for each value

type JsonArray

type JsonArray []json.RawMessage

type JsonObject

type JsonObject map[string]json.RawMessage

type KeyType

type KeyType int

KeyType represents either an object or an array

type Options

type Options struct {
	Prettify bool
	ShowErr  bool
	SplitTab bool
}

Options is just an option data for a process

type PathKey

type PathKey struct {
	// contains filtered or unexported fields
}

PathKey represents a path

Directories

Path Synopsis
cmd
jl command

Jump to

Keyboard shortcuts

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