jf(1)
π jf(1) β like, the JSON formatter of your dreams β¨
okay so bestie, welcome to jf, from the General Commands Manual β it's a template renderer that takes a template plus some values and spits out JSON (or YAML, we'll get there π). This page is literally gonna have you shipping valid JSON in like five minutes. no cap. π«Ά
πΈ USAGE πΈ
jf [OPTION]... [--] TEMPLATE [VALUE]... [NAME=VALUE]... [NAME@FILE]...
That's the whole shape of it: options first, then a TEMPLATE, then your positional VALUEs, then NAME=VALUE pairs, then NAME@FILE pairs. Order matters, bestie β more on that in RULES π
β¨ OPTIONS β¨
-β this is just an alias for-f -, i.e. read the template from stdin π§--β stop parsing CLI options. periodt, everything after this is not an option π-r,--rawβ print the raw rendered value without any formatting-p,--prettyβ pretty print the JSON formatted output (yes she's aesthetic β¨)-y,--yamlβ print the output as YAML instead of JSON π-h,--helpβ print this help message-v,--versionβ print the version number-f,--fileβ treat the template argument as a file to read from π
π¦ TEMPLATE π¦
So the template should render into valid YAML. That's the vibe check it has to pass. It can contain the following placeholders:
%%β a literal%character%s,%qβ read positional argument%-s,%-qβ read stdin%(NAME)s,%(NAME)qβ read named value from argument%(NAME=DEFAULT)s,%(NAME=DEFAULT)qβ placeholder with default value%(NAME@FILE)s,%(NAME@FILE)qβ read default value from file path%(NAME@-)s,%(NAME@-)qβ read default value from stdin%(NAME?)s,%(NAME?)qβ nullable placeholder that defaults to null%(NAME)?s,%(NAME)?qβ optional placeholder that defaults to blank%*s,%*qβ expand positional args as array items%*-s,%*-qβ expand stdin as array items%**s,%**qβ expand positional args as key value pairs%**-s,%**-qβ expand stdin as key value pairs%(NAME)*s,%(NAME)*qβ expand named args as array items%(NAME)**s,%(NAME)**qβ expand named args as key value pairs
And the golden rule, bestie: use placeholders with suffix q for safely quoted JSON string, and s for JSON values other than string. q = quoted = safe string π s = everything else π₯
π RULES π
- Pass values for positional placeholders in the same order as in the template β
- 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 - Pass values to stdin following the order and separate them with null byte (
) π«Ά - Use
NAME@FILEsyntax to read from file where FILE can be-for stdin - Do not pass positional values after named values π (she will not be happy)
- To allow merging arrays and objects via expansion, trailing comma after
sandq, if any, will be auto removed if no value is passed for the expandable placeholder β¨
π EXAMPLES π
okay these are iconic, let's go:
- Run:
jf %s 1 - Out:
1 - Run:
jf %q 1 - Out:
"1" - Run:
jf '{%**q}' one 1 two 2 three 3 - Out:
{"one":"1","two":"2","three":"3"} - Run:
seq 1 3 | xargs printf '%s ' | jf '[%*-s]' - Out:
[1,2,3] - Run:
jf "{%q: %(value=default)q, %(bar)**q}" foo value=bar bar=biz bar=baz
- Out:
{"foo":"bar","biz":"baz"} - Run:
jf "{str or bool: %(str)?q %(bool)?s, nullable: %(nullable?)q}" str=true
- Out:
{"str or bool":"true","nullable":null} - Run:
jf '{1: %s, two: %q, 3: %(3)s, four: %(four=4)q, "%%": %(pct?)q}' 1 2 3=3
- Out:
{"1":1,"two":"2","3":3,"four":"4","%":null}
π SHELL ALIASES π
You can set the following aliases in your shell, and honestly? you should. main character energy:
alias str='jf %q'alias arr='jf "[%*s]"'alias obj='jf "{%**s}"'
Then you can use them like this π
- Run:
str 1 - Out:
"1" - Run:
arr 1 2 3 - Out:
[1,2,3] - Run:
obj one 1 two 2 three 3 - Out:
{"one":1,"two":2,"three":3}
and then the flex π§:
- Run:
obj 1 2 3 "$(arr 4 "$(str 5)")"
- Out:
{"1":2,"3":[4,"5"]}
and that's the whole page, bestie β you ate that π β¨
sign-off szn: this was jf(1) from the General Commands Manual (that's the source + version tag, no date given on this one, she's mysterious like that π¦). mwah, go render something gorgeous ππ
π¦ where this page comes from
- nixos 26.05: jf 1.0.0
- nixpkgs unstable: jf 1.0.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms