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
Nixpkgs
Or download binary from the latest release.
Usage
Where TEMPLATE may contain the following placeholders:
%q,%(NAME)q,%(NAME=DEFAULT)qfor quoted and safely escaped JSON string.%s,%(NAME)s,%(NAME=DEFAULT)sfor JSON values other than string.
And [VALUE]... [NAME=VALUE]... are the values for the placeholders.
- Use
%sor%qsyntax to declare positional placeholders. - Use
%(NAME)sor%(NAME)qsyntax to declare named placeholders. - Use
%(NAME=DEFAULT)sor%(NAME=DEFAULT)qsyntax to declare default values for named placeholders. - Use
%%to escape a literal%character. - Pass values for positional placeholders in the same order as in the template.
- Pass values for named placeholders using
NAME=VALUEsyntax. - Do not declare or pass positional placeholders or values after named ones.
- To get the
jfversion number, runjf %v.
Example:
# jo hello=world
# {"hello":"world"}
# jo hello=$(jo beautiful=world)
# {"hello":{"beautiful":"world"}}
# jo d[m]=10 d[n]=20
# {"d":{"m":10,"n":20}}
# jo -d\|first_char_only a\|b=0 a\|c\|d=1 a\|d\|e[]=2 a\|d\|e[]=sam a\|c[f]@1 b\|e[]=hi
# {"a":{"b":0,"c":{"d":1,"f":true},"d":{"e":[2,"sam"]}},"b":{"e":["hi"]}}