tson is JSON viewer and editor written in Go

Related tags

JSON tson
Overview

tson

tson is JSON viewer and editor written in Go. This tool displays JSON as a tree and you can search and edit key or values.

Support OS

  • Mac
  • Linux

Installation

$ git clone https://github.com/skanehira/tson
$ cd tson && go install

Usage

# from file
$ tson < test.json

# from pipe
$ curl -X POST http://gorilla/likes/regist | tson

# from url(only can use http get mthod)
$ tson -url http://gorilla/likes/json

Use tson as a library in your application

You can use tson in your application as following.

package main

import (
	"fmt"

	tson "github.com/skanehira/tson/lib"
)

func main() {
	j := []byte(`{"name":"gorilla"}`)

	// tson.Edit([]byte) will return []byte, error
	res, err := tson.Edit(j)
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(string(res))
}

Keybinding

JSON tree

key description
j move down
k move up
g move to the top
G move to the bottom
ctrl-f page up
ctrl-b page down
h hide current node
H collaspe value nodes
l expand current node
L expand all nodes
r read from file
s save to file
a add new node
A add new value
d clear children nodes
e edit json with $EDITOR
q quit tson
Enter edit node
/ or f search nodes
? show helps
space expand/collaspe children nodes
ctrl-j move to next parent node
ctrk-k move to next previous node
ctrl-c quit tson

help

key description
j move down
k move up
g move to the top
G move to the bottom
ctrl-f page up
ctrl-b page down
q close help

About editing nodes

When editing a node value, the JSON value type is determined based on the value. For example, after inputed 10.5 and saving the JSON to a file, it will be output as a float type 10.5. If the value sorround with ", it will be output as string type always. The following is a list of conversion rules.

input value json type
gorilla string
10.5 float
5 int
true or false boolean
null null
"10" or "true" string

About adding new node

You can use a to add new node with raw json string.

For expample, you have following tree.

{array} <- your cursor in there
├──a
├──b
└──c

If you input {"name":"gorilla"} and press add button, then you will get new tree as following.

{array} <- your cursor in there
├──a
├──b
├──c
└──{object}
   └──name
      └──gorilla

Also, You can use A to add new value to current node.

For example, you have following tree.

{object} <- your cursor in there
└──name
   └──gorilla

If you input {"age": 26} and press add button, then you will get new tree as following.

{object} <- your cursor in there
├──name
│  └──gorilla
└──age
   └──26

Author

skanehira

You might also like...
Slow and unreliable JSON parser generator (in progress)

VivaceJSON Fast and reliable JSON parser generator Todo List parse fields parse types generate struct generate (keypath+key) to struct Value Mapping F

Kazaam was created with the goal of supporting easy and fast transformations of JSON data with Golang

kazaam Description Kazaam was created with the goal of supporting easy and fast transformations of JSON data with Golang. This functionality provides

Golang JSON decoder supporting case-sensitive, number-preserving, and strict decoding use cases

Golang JSON decoder supporting case-sensitive, number-preserving, and strict decoding use cases

Easy JSON parsing, stringifying, and accesing

Easy JSON parsing, stringifying, and accesing

json encoding and decoding

jx Package jx implements encoding and decoding of json [RFC 7159]. Lightweight fork of jsoniter. go get github.com/go-faster/jx Usage and examples Roa

A tool to aggregate and mine data from JSON reports of Go tests.

teststat A tool to aggregate and mine data from JSON reports of Go tests. Why? Mature Go projects often have a lot of tests, and not all of them are i

Search and output the value of JSON by it's path.

Search and output the value of JSON by it's path.

A simple GO module providing CRUD and match methods on a User "entity" stored locally as JSON

A simple GO module providing CRUD and match methods on a User "entity" stored locally as JSON. Created for GO language learning purposes. Once finishe

Abstract JSON for golang with JSONPath support

Abstract JSON Abstract JSON is a small golang package provides a parser for JSON with support of JSONPath, in case when you are not sure in its struct

Comments
  • Consider more conventional tree navigation behaviors

    Consider more conventional tree navigation behaviors

    I find it helpful when navigating any tree structure to be able to collapse and expand all nodes, but also go <-- (left) and --> (right) to move into & out of the structure's depth.

    Right now, LEFT and RIGHT arrow keys only go UP and DOWN, but would you consider having LEFT and RIGHT jump directly to the adjacent parent/child node in that direction?

    Also, the key bindings are really unintuitive for non-vim users. Could we consider using SPACEBAR and SHIFT-* (etc.) for certain actions like expanding/collapsing current node, jumping up or down a page or element, etc? I don't have anything too concrete in mind, but it's a little tricky to use right out of the box. I have to keep referencing the table in the readme, but I feel like I should just be able to figure it out with my arrow keys and spacebar and ctrl/shift keys.

    Additionally, the "Collapse all nodes" (H) doesn't seem to be very helpful, as it just replaces everything with a . ... which I can then edit... anyway, I just think there's some room for significant improvement here in the UI.

    opened by mholt 5
  • Refactor for use as a library

    Refactor for use as a library

    I know this sounds a bit crazy, but it would be great if this could be used as a library. Basically, separate out the parts of this tool that deal with the command line, and put the code that actually does the TUI stuff and tree nav in its own package.

    For example (without having given it too much though), this would be very nice:

    myJSON := []byte{...}
    updatedJSON, err := tson.Edit(myJSON)
    // a TUI screen would cover the terminal at this point,
    // and relinquish itself when done editing, while
    // returning the resulting JSON bytes
    

    I could see myself embedding something like this into Caddy 2, which is configured entirely by JSON. But only if it can be used as a library like this.

    Imagine starting up your web server in some interactive/dashboard mode, and being able to watch it in real-time in your terminal (kind of like what htop does, but just for your server), while being able to edit its configuration right there as well! Super useful for development too!

    Anyway, I'm excited about this project, I hope you'll keep developing it.

    enhancement 
    opened by mholt 3
  • closed request body

    closed request body

    request body must be closed else will there be a memory leak

    https://stackoverflow.com/questions/33238518/what-could-happen-if-i-dont-close-response-body-in-golang/33238755 https://golang.org/pkg/net/http/ https://stackoverflow.com/questions/23928983/defer-body-close-after-receiving-response

    opened by vaibhav2ghadge 1
Releases(1.3.3)
Owner
skanehira
Like Vim, Go. Many CLI/TUI Tools, Vim plugin author.
skanehira
Json-go - CLI to convert JSON to go and vice versa

Json To Go Struct CLI Install Go version 1.17 go install github.com/samit22/js

Samit Ghimire 7 Jul 29, 2022
JSON Spanner - A Go package that provides a fast and simple way to filter or transform a json document

JSON SPANNER JSON Spanner is a Go package that provides a fast and simple way to

null 6 Sep 14, 2022
Get JSON values quickly - JSON parser for Go

get json values quickly GJSON is a Go package that provides a fast and simple way to get values from a json document. It has features such as one line

Josh Baker 11.4k Nov 27, 2022
JSON diff library for Go based on RFC6902 (JSON Patch)

jsondiff jsondiff is a Go package for computing the diff between two JSON documents as a series of RFC6902 (JSON Patch) operations, which is particula

William Poussier 210 Nov 17, 2022
Fast JSON encoder/decoder compatible with encoding/json for Go

Fast JSON encoder/decoder compatible with encoding/json for Go

Masaaki Goshima 1.9k Nov 23, 2022
Fast JSON parser and validator for Go. No custom structs, no code generation, no reflection

fastjson - fast JSON parser and validator for Go Features Fast. As usual, up to 15x faster than the standard encoding/json. See benchmarks. Parses arb

Aliaksandr Valialkin 1.7k Nov 23, 2022
Fast and flexible JSON encoder for Go

Jettison Jettison is a fast and flexible JSON encoder for the Go programming language, inspired by bet365/jingo, with a richer features set, aiming at

William Poussier 138 Nov 20, 2022
/ˈdʏf/ - diff tool for YAML files, and sometimes JSON

dyff is inspired by the way the old BOSH v1 deployment output reported changes from one version to another by only showing the parts of a YAML file that change.

null 745 Nov 24, 2022
HuJSON: JSON for Humans (comments and trailing commas)

HuJSON - Human JSON The HuJSON decoder is a JSON decoder that also allows comments, both /* ... */ and // to end of line trailing commas on arrays and

Tailscale 425 Nov 11, 2022
JSONata in Go Package jsonata is a query and transformation language for JSON

JSONata in Go Package jsonata is a query and transformation language for JSON. It's a Go port of the JavaScript library JSONata.

Blues Inc 35 Nov 8, 2022