dysolution / jprint

a simple CLI JSON generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jprint

jprint is a simple CLI JSON generator inspired by jo. It takes an set of key/value pairs in the format key=value and prints out a corresponding object in JSON.

Examples

Per the JSON spec, keys are strings. All values are strings by default.

$ jprint foo=bar
{
    "foo": "bar"
}

Integers and floating-point numbers are detected and converted into 64-bit representations, and boolean values are autodetected:

$ jprint tau=6.283185 right_out=5 proprietary=false
{
    "proprietary": false,
    "right_out": 5,
    "tau": 6.283185
}

jprint uses Go's json.MarshalIndent, which sorts keys alphabetically by default:

$ jprint foo=bar num=3 a_few_numbers=[1,2,3]
{
    "a_few_numbers": [
        1,
        2,
        3
    ],
    "foo": "bar",
    "num": 3
}

You can specify the number of spaces to indent pretty-printed JSON:

$ jprint -i 2 foo=bar
{
  "foo": "bar"
}

Forcing single-line output makes it easier to embed jprint output in other commands, logs, etc.:

$ jprint -o foo=bar
{"foo":"bar"}

Installation

$ git clone https://github.com/dysolution/jprint.git
$ cd jprint
$ go install

Tests

$ ./test.sh

TODO

  • support nesting, e.g., jprint bar=$(jprint foo=3)

License

MIT

About

a simple CLI JSON generator

License:MIT License


Languages

Language:Go 99.2%Language:Shell 0.8%