Skip to content
/ je Public

The json-editor is an easy-to-use json query and editing tool.

License

Notifications You must be signed in to change notification settings

sycki/je

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Json editor

The Json editor is an easy-to-use json query and editing tool that you can use in command line and golang projects.

Documents

Install

curl -Lo je https://sycki.com/f/bin/je          // for linux
curl -Lo je https://sycki.com/f/bin/je-darwin   // for mac
chmod +x je
mv je /usr/local/bin/je                         // move to your PATH

Use in command line

Get

  • Get string
    echo '{"k1":"v1","k2":2,"k3":[{"k31":"v31"},{"k32":"v32"},{"k33":"v33"}]}' | je .k1
    v1
  • Get string
    echo '{"k1":"v1","k2":2,"k3":[{"k31":"v31"},{"k32":"v32"},{"k33":"v33"}]}' | je .k2
    2
  • Get length string
    echo '{"k1":"v1","k2":2,"k3":[{"k31":"v31"},{"k32":"v32"},{"k33":"v33"}]}' | je .k3.#
    3
  • Get string
    echo '{"k1":"v1","k2":2,"k3":[{"k31":"v31"},{"k32":"v32"},{"k33":"v33"}]}' | je .k3.0.k31
    v31

Set

  • Set struct
    echo '{"k1":{"k11":"v11","k12":"v12"},"k2":"v2"}' | je .k2 '{"k21":"v21"}'
    {"k1":{"k11":"v11","k12":"v12"},"k2":{"k21":"v21"}}
  • Set array
    echo '{"k1":{"k11":"v11","k12":"v12"},"k2":"v2"}' | je .k2 '[{"k21":"v21"}]'
    {"k1":{"k11":"v11","k12":"v12"},"k2":[{"k21":"v21"}]}
  • Set int
    echo '{"k1":{"k11":"v11","k12":"v12"},"k2":"v2"}' | je .k2 '5'
    {"k1":{"k11":"v11","k12":"v12"},"k2":5}
  • Set string
    echo '{"k1":{"k11":"v11","k12":"v12"},"k2":"v2"}' | je .k2 '"5"'
    {"k1":{"k11":"v11","k12":"v12"},"k2":"5"}
  • Set string
    echo '{"k1":{"k11":"v11","k12":"v12"},"k2":"v2"}' | je .k2 \"5\"
    {"k1":{"k11":"v11","k12":"v12"},"k2":"5"}
  • Set string
    echo '{"k1":{"k11":"v11","k12":"v12"},"k2":"v2"}' | je .k2 v0
    {"k1":{"k11":"v11","k12":"v12"},"k2":"v0"}

Use in golang code

More demo see je_test.go

Get

import github.com/sycki/je

func main() {
    str := `{"k1":"v1","k2":2,k3":[{"k31":"v31"},{"k32":"v32"},{"k33":"v33"}]}`
    r := je.Get(str, ".k3.0.k31")
    println(r) // v31
}

Set

import github.com/sycki/je

func main() {
    str := `{"k1":"v1","k2":2,k3":[{"k31":"v31"},{"k32":"v32"},{"k33":"v33"}]}`
    r := je.Set(str, ".k3", 3)
    println(r) // {"k1":"v1","k2":2,k3":3}
}

About

The json-editor is an easy-to-use json query and editing tool.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published