/jsonof

convert command line args to JSON

Primary LanguageGo

jsonof

convert command line args to JSON

Example:

$ ./jsonof --pretty id: @uuid created: @now foo: bar isNew: true intValue: 123 floatVal: 23.88 doNull: null andNil: nil
{
    "andNil": null,
    "created": "2020-12-12T20:52:57Z",
    "doNull": null,
    "floatVal": 23.88,
    "foo": "bar",
    "id": "56f2b89f-64f9-497f-ac0f-20ad6bac21ce",
    "intValue": 123,
    "isNew": true
}

Handy for building JSON from shell:

$ ./jsonof -p files: * pwd: `pwd`
{
    "files": [
        "Makefile",
        "README.md",
        "go.mod",
        "go.sum",
        "jsonof",
        "jsonof.go",
        "jsonof.lnx"
    ],
    "pwd": "/Users/pkelly/zorkspace/fxr/jsonof"
}

Mac & Linux binaries checked in.

bash v zsh

It turns out that [ and ] mean something to zsh, and it doesn't like you using them as "normal" arguments.

To get around this (in zsh, not a problem in bash), you can prefix your command with noglob, e.g.:

noglob jsonof [ apple banana ]