Skip to content
This repository was archived by the owner on Apr 11, 2022. It is now read-only.

Created Package out of application #14

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions .idea/jsonui.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.2.0 2021.06.11
- Moved cmd to jsonui-cmd
- Made package out of jsonui, enabling others with json files to use
Easy: just run jsonui.Interactive([]byte with json.)
## 1.0.1 2018.09.15
- fixes `null` rendering
- adds binary builds
Expand Down
37 changes: 36 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,42 @@

![](img/jsonui.gif)

## Import into your application
jsonui can now be imported into your application --
```
...
jsonBytes,err := ioutil.ReadFile("jsonfile.json")
errorhandle(err)
jsonpath:=jsonui.Interactive(jsonBytes)
fmt.Println(jsonpath)
...
```
When it runs, scroll down to the section, press x to execute. The output will look like this:
```
] $ cat test.json | jsonui
JSON Path: address.gateways
```
And then the user will be able to extract json using another utility called 'jj'
```
]$ cat test.json | jj address.gateways
["Sopron", "Vienna", "Budapest"]
```

You could also use the jsonpath variable above for other packages like gjson or sjson to get / set values.
## Install
This Version:
`git clone https://github.com/rmasci/jsonui.git`
cd jsonui/jsonui-cmd
make

Original:
`go get -u github.com/gulyasm/jsonui`

## Binary Releases
This Version:
[Binary releases are availabe](https://github.com/rmasci/jsonui/releases)

Original:
[Binary releases are availabe](https://github.com/gulyasm/jsonui/releases)

## Usage
Expand Down Expand Up @@ -42,11 +74,14 @@ Expand all nodes

#### `C`
Collapse all nodes

### `x`
Execute. Will give you the JSON Path to use with jj command.
[https://github.com/tidwall/jj](https://github.com/tidwall/jj)
#### `q/Ctrl+C`
Quit jsonui



## Acknowledgments
Special thanks for [asciimoo](https://github.com/asciimoo) and the [wuzz](https://github.com/asciimoo/wuzz) project for all the help and suggestions.

33 changes: 33 additions & 0 deletions jsonui-cmd/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
compilerFlag=-gcflags=-trimpath=$(shell pwd) -asmflags=-trimpath=$(shell pwd)
goFiles=main.go
gomod=off
all: mac linux windows freebsd netbsd openbsd pi

windows:$(goFiles)
GO111MODULE=$(gomod) GOOS=windows GOARCH=386 go build $(compilerFlag) -o ../../jsonui-release/win32-jsonui.exe $(goFiles)
GO111MODULE=$(gomod) GOOS=windows GOARCH=amd64 go build $(compilerFlag) -o ../../jsonui-release/win64-jsonui.exe $(goFiles)

linux: $(goFiles)
GO111MODULE=$(gomod) GOOS=linux GOARCH=386 go build $(compilerFlag) -o ../../jsonui-release/lin32-jsonui $(goFiles)
GO111MODULE=$(gomod) GOOS=linux GOARCH=amd64 go build $(compilerFlag) -o ../../jsonui-release/lin64-jsonui $(goFiles)

pi: $(gofiles)
GO111MODULE=$(gomod) GOOS=linux GOARCH=arm GOARM=6 go build $(compilerFlag) -o ../../jsonui-release/jsonui-pi $(goFilesU)

mac:
GO111MODULE=$(gomod) GOOS=darwin GOARCH=amd64 go build $(compilerFlag) -o ../../jsonui-release/mac-jsonui $(goFiles)

freebsd: $(goFiles)
GO111MODULE=$(gomod) GOOS=freebsd GOARCH=386 go build $(compilerFlag) -o ../../jsonui-release/freebsd32-jsonui $(goFiles)
GO111MODULE=$(gomod) GOOS=freebsd GOARCH=amd64 go build $(compilerFlag) -o ../../jsonui-release/freebsd64-jsonui $(goFiles)

netbsd: $(goFiles)
GO111MODULE=$(gomod) GOOS=freebsd GOARCH=386 go build $(compilerFlag) -o ../../jsonui-release/netbsd32-jsonui $(goFiles)
GO111MODULE=$(gomod) GOOS=freebsd GOARCH=amd64 go build $(compilerFlag) -o ../../jsonui-release/netbsd64-jsonui $(goFiles)

openbsd: $(goFiles)
GO111MODULE=$(gomod) GOOS=openbsd GOARCH=386 go build $(compilerFlag) -o ../../jsonui-release/openbsd32-jsonui $(goFiles)
GO111MODULE=$(gomod) GOOS=openbsd GOARCH=amd64 go build $(compilerFlag) -o ../../jsonui-release/openbsd64-jsonui $(goFiles)

solaris: $(goFiles)
GO111MODULE=$(gomod) GOOS=solaris GOARCH=amd64 go build $(compilerFlag) -o ../../jsonui-release/sol-jsonui $(goFiles)
40 changes: 40 additions & 0 deletions jsonui-cmd/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"fmt"
"io/ioutil"
"os"

"github.com/rmasci/jsonui"
"github.com/spf13/pflag"
)

func main() {
var inFile string
var jsonByte []byte
var err error
pflag.StringVarP(&inFile, "file", "f", "", "JSON File to parse")
pflag.Parse()
if inFile != "" {
jsonByte, err = ioutil.ReadFile(inFile)
if err != nil {
fmt.Println("Could not read file", err)
os.Exit(1)
}
} else {
stat, _ := os.Stdin.Stat()
if (stat.Mode() & os.ModeCharDevice) == 0 {
jsonByte, err = ioutil.ReadAll(os.Stdin)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
}
if len(jsonByte) <= 1 {
fmt.Println("No Data")
os.Exit(1)
}
jp := jsonui.Interactive(jsonByte)
fmt.Println("JSON Path:", jp)
}
Loading