simple json formatter
- go 1.19
clone this repo
$ git clone https://github.com/x0y14/jsonfmt.git
$ cd jsonfmt
go build (To place the executable file in the bin directory)
$ mkdir -p bin
$ go build -o ./bin/jsonfmt ./cmd/jsonfmt/main.go
$ jsonfmt <flags> <args>
Indentation is based on four spaces, Print only.
$ ./bin/jsonfmt -p -i 4 ./samples/sample1.json
Indentation is based on four spaces, Save the formatted data as a name.
$ ./bin/jsonfmt -o ./samples/sample1_formatted.json -i 4 ./samples/sample1.json
Indentation is based on four spaces, Overwrite the original file with formatted data
$ ./bin/jsonfmt -w ./samples/sample1.json
before
{"name": "john", "age": 18, "sex": "male", "come-from": "usa", "weight": 61.2, "height": 175.0, "parent": {},"partner": null, "married": false, "children": []}
after (./bin/jsonfmt ./samples/sample3.json)
{
"name": "john",
"age": 18,
"sex": "male",
"come-from": "usa",
"weight": 61.2,
"height": 175,
"parent": {},
"partner": null,
"married": false,
"children": []
}
If multiple settings are made, priority is given from the top to the bottom.
- output / o
boolean, - overwrite / w
boolean - print / p
boolean, default mode
- ident / i
int, default is 2
- help
- Sorting elements