jl

package module
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2023 License: MIT Imports: 5 Imported by: 0

README

go-jl

MIT License go-jl CI go-jl report card

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
{
 "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
{
    "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, --no-prettify  Not prettify the JSON. Prettified by default
  -e, --show-error   Set this option to show errors, muted by default
  -n, --split-lf     Split line-feed \n in each element
  -t, --split-tab    Split tabs in each element
  -v, --version      Display version and build info and exit

Installation

homebrew install

If you are using Mac:

brew tap bayashi/tap
brew install bayashi/tap/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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Process

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

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

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 {
	NoPrettify bool
	ShowErr    bool
	SplitTab   bool
	SplitLF    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

Jump to

Keyboard shortcuts

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