jf
jf is a jo alternative, A small utility to safely format and print JSON objects in the commandline.
However, unlike jo, where you build the JSON object by nesting jo outputs,
jf works similar to printf, i.e. it expects the template in YAML format as the first argument, and then the values for the placeholders as subsequent arguments.
INSTALL
Cargo
As a CLI tool
Or as a library:
Nixpkgs
Binaries
USAGE
Where TEMPLATE may contain the following placeholders:
%qquoted and safely escaped JSON string%sJSON values other than string%vthejfversion number%%a literal%character%Renable raw mode - render but do not format output%Yenable pretty YAML mode - format output into pretty YAML%Jenable pretty JSON mode - format output into pretty JSON
And [VALUE]... [NAME=VALUE]... [NAME@FILE]... are the values for the placeholders.
SYNTAX
%s%qread positional argument%-s%-qread stdin%(NAME)s%(NAME)qread named value from argument%(NAME=DEFAULT)s%(NAME=DEFAULT)qplaceholder with default value%(NAME@FILE)s%(NAME@FILE)qread default value from file path%(NAME@-)s%(NAME@-)qread default value from stdin%(NAME?)s%(NAME?)qnullable placeholder that defaults to null%(NAME)?s%(NAME)?qoptional placeholder that defaults to blank%*s%*qexpand positional args as array items%*-s%*-qexpand stdin as array items%**s%**qexpand positional args as key value pairs%**-s%**-qexpand stdin as key value pairs%(NAME)*s%(NAME)*qexpand named args as array items%(NAME)**s%(NAME)**qexpand named args as key value pairs
RULES
- Pass values for positional placeholders in the same order as in the template.
- Pass values to stdin following the order and separate them with null byte (
\0). - Pass values for named placeholders using
NAME=VALUEsyntax. - Pass values for named array items using
NAME=ITEM_Nsyntax. - Pass values for named key value pairs using
NAME=KEY_N NAME=VALUE_Nsyntax. - Use
NAME@FILEsyntax to read from file where FILE can be-for stdin. - Do not declare or pass positional placeholders or values after named ones.
- To allow merging arrays and objects via expansion, trailing comma after
sandqwill be auto removed after the expansion if no value is passed for the placeholder.
EXAMPLES
# 1
# "1"
# {"one":"1","two":"2","three":"3"}
| |
# [1,2,3]
# {"foo":"bar","biz":"baz"}
# {"str or bool":"true","nullable":null}
# {"1":1,"two":"2","3":3,"four":"4","%":null}
SHELL ALIASES
You can set the following aliases in your shell:
Then you can use them like this:
# "1"
# [1,2,3]
# {"one":1,"two":2,"three":3}
# {"1":2,"3":[4,"5"]}
RUST LIBRARY
let json = match format ;