https://github.com/sarathsp06/gojson
Command line utility to handle JSON in command line.
https://github.com/sarathsp06/gojson
cli cli-app golang json
Last synced: 11 months ago
JSON representation
Command line utility to handle JSON in command line.
- Host: GitHub
- URL: https://github.com/sarathsp06/gojson
- Owner: sarathsp06
- License: mit
- Created: 2019-02-28T16:06:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-04-30T09:57:52.000Z (about 2 years ago)
- Last Synced: 2024-06-20T19:21:16.896Z (about 2 years ago)
- Topics: cli, cli-app, golang, json
- Language: Go
- Homepage:
- Size: 38.7 MB
- Stars: 7
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## GoJSON [](https://goreportcard.com/report/github.com/sarathsp06/gojson)  [](https://github.com/sarathsp06/gojson/actions/workflows/go.yml)
🎉 GoJSON 🚀 - A command-line utility to jazz up your JSON handling!
🛠️ Built for fun during a never-ending 3-hour meeting where I just nodded along. 🙃 If you're scouting for some seriously useful JSON command-line tools, check out the list below!
* [dsq](https://github.com/multiprocessio/dsq) - Tool for running SQL queries against JSON, CSV, Excel, Parquet, and more.
* [fx](https://github.com/antonmedv/fx) - A interactive terminal tool.
* [jo](https://github.com/jpmens/jo) - A small utility to create JSON objects
* [jsoncat](https://github.com/pantuza/jsoncat) - Pretty-print Json in terminal with colors and adjusting tabs size.
* [jq](http://stedolan.github.io/jq/) - A lightweight and flexible command-line JSON processor.
* [json](http://trentm.com/json/) - A "json" command for massaging JSON on your Unix command line.
* [jshon](http://kmkeen.com/jshon/) - A parser designed for maximum convenience within the shell.
* [jarg](http://jdp.github.io/jarg/) - Shorthand JSON and form encoding syntax in the shell.
* [jsawk](https://github.com/micha/jsawk) - Like awk, but for JSON.
* [json-dotenv](https://github.com/decryptus/json-dotenv) - Manipulate and extract envfiles in json format.
* [gron](https://github.com/tomnomnom/gron) - Convert a JSON file into discrete assignments that are greppable.
* [jid](https://github.com/simeji/jid) - Incremental Digger. Drill down JSON interactively by using filtering queries like jq.
* [jiq](https://github.com/fiatjaf/jiq) - It's `jid` with `jq`. You can drill down interactively by using `jq` filtering queries.
* [jv](https://github.com/maxzender/jv) - jv (for jsonviewer) helps you view your JSON.
* [jl](https://github.com/chrisdone/jl) - Functional sed for JSON.
* [oj](https://github.com/ohler55/ojg) - A fast and flexible command line JSON processor.
* [visidata](https://github.com/saulpw/visidata) - A terminal spreadsheet-like tool for interactively exploring data.
### What gojson does
- [x] Retrieve nested objects
- [x] Pretty print JSON
- [x] Validate JSON
- [x] Aggregate functions
## Installing
**Go Dev version**
```sh
go install github.com/sarathsp06/gojson@latest
```
**Binray Release**
[download](https://github.com/sarathsp06/gojson/releases) 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:
```sh
$ echo '{"name":{"first":"Sarath","last":"Pillai"}}' | gojson name.last
"Pillai"
```
- Get a block of JSON:
```sh
$ echo '{"name":{"first":"Sarath","last":"Pillai"}}' | gojson name
{
"first": "Sarath",
"last": "Pillai"
}
```
- Try to get a non-existent key:
```sh
$ echo '{"name":{"first":"Sarath","last":"Pillai"}}' | gojson names
nil
```
- Get an array value by index:
```sh
$ echo '{"people":[{"name":"saratha"},{"name":"syam"}]}' | gojson people.1.name
"syam"
```
- Projection from a slice
```sh
$ echo '{"people":[{"name":"saratha"},{"name":"syam"},{"name":"singh"},{"name":"ping"}]}' | gojson people.2:.name
[
"singh",
"ping"
]
```
- Slice of array
```sh
$ echo '{"people":[{"name":"saratha"},{"name":"syam"},{"name":"singh"},{"name":"ping"}]}' | gojson people.2:5
[
{
"name": "singh"
},
{
"name": "ping"
}
]
```
- Handling JSON key names with a `.`:
```sh
$ echo '{"first.name":"Sarath","last.name":"Pillai"}' | gojson \"first.name\"
"Sarath"
```