Giter Site home page Giter Site logo

tson's Introduction

This repository is no longer to develop.

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

tson's People

Contributors

skanehira avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

tson's Issues

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.

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.