Skip to content
/ gojson Public
forked from sarathsp06/gojson

Command line utility to handle JSON in command line.

License

Notifications You must be signed in to change notification settings

Rahil43/gojson

 
 

Repository files navigation

GoJSON Build Status Quality Gate Status Go Report Card Last Commit

GoJSON is a command line utility to handle json in command line.

What it does

  • Retrieve nested objects
  • Pretty print JSON
  • Validate JSON
  • Aggregate functions

Installing

Go Dev version

$ go get -u github.com/sarathsp06/gojson

Binray Release

download and use the binary as such for your platform

Tip:

In unix move the binary to PATH

Key Syntax

  • Key is a set of . seperated nested values
  • Can use 0-n numbers to refer to index in arrays
  • Can use lower:upper syntax to refer to a range of an array. Eg: players.1:3
  • Can use keys of inner objects directly on arrays or range of them. Eg: players.name where players is an array

Usage Examples

Getting a value
  • Get a string:
$ echo '{"name":{"first":"Sarath","last":"Pillai"}}' | gojson name.last
"Pillai"
  • Get a block of JSON:
$ echo '{"name":{"first":"Sarath","last":"Pillai"}}'  | gojson name

{
  "first": "Sarath",
  "last": "Pillai"
}
  • Try to get a non-existent key:
$ echo '{"name":{"first":"Sarath","last":"Pillai"}}' | gojson names
nil
  • Get an array value by index:
$ echo '{"people":[{"name":"saratha"},{"name":"syam"}]}' | gojson people.1.name                                               
"syam"
  • Projection from a slice
$ echo '{"people":[{"name":"saratha"},{"name":"syam"},{"name":"singh"},{"name":"ping"}]}' | gojson people.2:.name 
[
  "singh",
  "ping"
]
  • Slice of array
$ echo '{"people":[{"name":"saratha"},{"name":"syam"},{"name":"singh"},{"name":"ping"}]}' | gojson people.2:5     
[
  {
    "name": "singh"
  },
  {
    "name": "ping"
  }
]

About

Command line utility to handle JSON in command line.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 94.7%
  • Makefile 5.3%