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:
%qfor quoted and safely escaped JSON string.%sfor JSON values other than string.%vfor thejfversion number.%%for a literal%character.
And [VALUE]... [NAME=VALUE]... are the values for the placeholders.
SYNTAX
%s,%qfor posiitonal placeholders.%(NAME)s,%(NAME)qfor named placeholders.%(NAME=DEFAULT)s,%(NAME=DEFAULT)qfor placeholders with default values.%?(NAME)s,%?(NAME)qfor optional placeholders.%*s,%*qfor variable number of array items.%**s,%**qfor variable number of key value pairs.
RULES
- 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.
- Nesting placeholders is prohibited.
- Variable length placeholder should be the last placeholder in a template.
EXAMPLES
# 1
# "1"
# [1,2,3]
# {"one":"1","two":"2","three":"3"}
# {"foo":"bar"}
# {"str_or_bool":"true","optional":null}
# {"1":1,"two":"2","3":3,"four":"4","%":"100%"}
Rust Library
let json = match format ;